A boring train journey
Time Limit: 2.0 s
Memory Limit: 256.0 MB
Description
Today is a special day for Alice because he is going to attend in a IUPC in chittagong. So he is waiting for the train to arrive at Shaistaganj station. But unfortunately the train will arrive 2 hours late for some railway traffic management fault. While waiting for the train to be arrived Alice is being bored. To overcome this boredom he starts to think if he can design an algorithm which can increase the efficiency of the railway traffic system and reduce the management issue described below.
Sylhet to Chittagong railway is a single lane rail track, which means two train coming from opposite direction can not overpass without an extra lane. There are N stations from Sylhet to chittagong starting from Sylhet station at 1st position and ending at Chittagong at n th position. In each station there is an extra lane of length \(Bi\) where two train having minimum length less than Bi coming from opposite direction can overtake each other.
now consider a situation where, A train departures from sylhet station for chittagong and at the same time another train departures from chittagong station for sylhet at a same constant speed. So eventually one of the train has to wait in a station to overpass another else they will end up in a face to face collision.
What Alice is trying to do, is to make a program which can calculate the positions of both train and select a station in which thay can overpass each other safely and the train reaches that particular station first has to wait minimum unit of time.
note: both train travels one unit of distance in one unit of time. if the length of the extra lane of a station is strictly larger than the train having minimum length only then the station can be used to overpass trains. it is possible that both train enters a station from opposite side at the same time.
Input
First line of input takes an integer \(T\) : number of testcases
Each testcase consists 4 lines of input
first line of each testcase takes two integer \(T1\) and \(T2\) : length of two train (in meters)
second line of each testcase takes an integer \(N\) : number of stations
third line of each testcase takes \(N\) integers A1,A2,A3.....An : the positions of each station in positive x coordinate. first station is always in 0.
fourth line of each testcase takes \(N\) integers B1,B2,B3....Bn : the length of the extra lane in i-th station
1 <= \(T1\) , \(T2\) <= 100
1 <= \(N\) <= 10^5
0 <= \(Ai\), \(Bi\) <=10^9
it is guaranteed that sum of N over all testcase will not exceed 10^5
Output
Print a single integer in each of the \(T\) line : the minimum unit of time a train has to wait in any of the station to overpass other train. if it is impossible to overpass the the trains print -1
Sample
Input | Output |
---|---|
|
|
in the first testcase, the second train will have to wait 2 unit of time in the 3rd station.
in the second testcase length of all the additional tracks are less than the minimum length of a train. so it is impossible for those trains to overpass each other in any of the station.
Information
- ID
- 1030
- Difficulty
- 7
- Category
- Ad_Hoc Click to Show
- Tags
- (None)
- # Submissions
- 24
- Accepted
- 7
- Accepted Ratio
- 29%
- Uploaded By
Related
In following contests: