The first overtake
Practice
1.6 (11 votes)
Basic math
Algorithms
Math
Problem
54% Success 282 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code
In a car race, there are N cars 1,2 ... N where the ith car is moving with a speed of (N - i + 1). All the cars are moving in the same direction.
The current position of the cars is Xi. Determine the time at which the first overtake takes place.
Note: Overtake is defined as the place when a car crosses another car that is ahead of it.
Input format
- Each test contains multiple test cases.
- The first line contains the number of test cases T.
- The first line of each test case contains two space-separated integers N and M representing the number of cars and the length of the circular path.
- The second line of each test case contains N integers where the ith integer is Xi representing the position of the ith car on the track.
Output format
For each test case, print a single line containing one integer representing the time at which the first overtake takes place.
Constraints
\(1 ≤ T ≤ 10^4 \\ 2 ≤ N ≤ 10^5 \\ 1 ≤ M ≤ 10^9\\ 0 ≤ X_i ≤10^9 \\ X_i < X_{i+1} \text{ for } (1 ≤ i ≤ N-1)\\ \text{It is guaranteed that the sum of N over all test cases does not exceed }2\cdot 10^5\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
79 votes
Tags:
MathematicsBasic MathVery-EasyMathematics
Points:10
16 votes
Tags:
Very-EasyVery Easy
Points:10
1 votes
Tags:
Basic MathC++MathObservation
Editorial