Problem Statement | |||||||||||||
This problem contains images best viewed from the applet.
A train is moving in the positive direction of the x-axis. The train consists of nCarriages carriages of equal length. Initially, at time 0, the coordinate of the rightmost end of the last carriage is length, the coordinate of the rightmost end of the second to last carriage is 2 * length, and so on. There is a robber located on the leftmost point of the roof of the last carriage.
There are an infinite number of low bridges above the railway. Each bridge belongs to one bridge sequence. The k-th sequence consists of bridges located at the coordinates offset[k] + period[k] * j, for all non-negative integers j.
The train moves at a constant speed of trainSpeeed units per second, and the robber has a maximal speed of robberSpeed units per second. The robber cannot walk through the bridges when he is on the roof because they are too low. Therefore, whenever the robber is at the same coordinate as a bridge, he must either be between two carriages or at either end of the train. This allows him to duck and jump down into a safe area. The robber's goal is to travel to the rightmost point of the first carriage as quickly as possible. He will stop walking and jump off the train when he reaches the rightmost point of the first carriage, or when nBridges have passed above him - whichever comes first. Return the position of the robber on the x-axis when he exits the train. The offsets and periods of the bridge sequences are given in the String[]s offset and period. Each element of offset and period contains a space separated list of integers. The ith integers in offset and period are the offset and period of the ith bridge sequence. See example 0 for clarification. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | It is possible for multiple bridges to be located in the same position. | ||||||||||||
- | A return value with either an absolute or relative error of less than 1.0E-9 is considered correct. | ||||||||||||
Constraints | |||||||||||||
- | length will be between 1 and 1000000, inclusive. | ||||||||||||
- | nCarriages will be between 1 and 1000000, inclusive. | ||||||||||||
- | offset will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of offset will contain between 1 and 50 characters, inclusive. | ||||||||||||
- | period will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of period will contain between 1 and 50 characters, inclusive. | ||||||||||||
- | Each element of offset and period will contain one or more integers without leading zeroes separated by single spaces. | ||||||||||||
- | Each integer in offset and period will be between 1 and 1000000, inclusive. | ||||||||||||
- | offset and period will contain the same number of integers. | ||||||||||||
- | trainSpeed will be between 1 and 1000000, inclusive. | ||||||||||||
- | robberSpeed will be between 1 and 1000000, inclusive. | ||||||||||||
- | nBridges will be between 1 and 1000000, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|