As a professional competitive programmer, Solve this problem: Mualani loves surfing on…
- User
As a professional competitive programmer, Solve this problem:
Mualani loves surfing on her sharky surfboard!
Mualani's surf path can be modeled by a number line. She starts at position 1 , and the path ends at position L . When she is at position x with a jump power of k , she can jump to any integer position in the interval [x,x+k] . Initially, her jump power is 1 .
However, her surf path isn't completely smooth. There are n hurdles on her path. Each hurdle is represented by an interval [l,r] , meaning she cannot jump to any position in the interval [l,r] .
There are also m power-ups at certain positions on the path. Power-up i is located at position xi and has a value of vi . When Mualani is at position xi , she has the option to collect the power-up to increase her jump power by vi . There may be multiple power-ups at the same position. When she is at a position with some power-ups, she may choose to take or ignore each individual power-up. No power-up is in the interval of any hurdle.
What is the minimum number of power-ups she must collect to reach position L to finish the path? If it is not possible to finish the surf path, output −1 .
Input The first line contains an integer t (1≤t≤104 ) — the number of test cases.
The first line of each test case contains three integers n , m , and L (1≤n,m≤2⋅105,3≤L≤109 ) — the number of hurdles, the number of power-ups, and the position of the end.
The following n lines contain two integers li and ri (2≤li≤ri≤L−1 ) — the bounds of the interval for the i 'th hurdle. It is guaranteed that ri+1<li+1 for all 1≤i<n (i.e. all hurdles are non-overlapping, sorted by increasing positions, and the end point of a previous hurdle is not consecutive with the start point of the next hurdle).
The following m lines contain two integers xi and vi (1≤xi,vi≤L ) — the position and the value for the i 'th power-up. There may be multiple power-ups with the same x . It is guaranteed that xi≤xi+1 for all 1≤i<m (i.e. the power-ups are sorted by non-decreasing position) and no power-up is in the interval of any hurdle.
It is guaranteed the sum of n and the sum of m over all test cases does not exceed 2⋅105 .
Output For each test case, output the minimum number of power-ups she must collect to reach position L . If it is not possible, output −1 .
Solve it using C++
- Assistant