#P1941. [NOIP 2014 提高组] 飞扬的小鸟
[NOIP 2014 提高组] 飞扬的小鸟
Description
Flappy Bird is a once-popular casual mobile game. The player needs to continuously control the tapping frequency to adjust the bird’s altitude so that it passes through the gaps between the pipes on the right side of the screen. If the bird accidentally hits a pipe or falls to the ground, the game ends in failure.
To simplify the problem, we modify the game rules as follows:
The game interface is a 2D plane with length and height , containing pipes (pipe width is ignored).
The bird always moves within the game interface. It starts from any integer height on the left edge of the interface, and the game is completed when it reaches the right edge.
In each unit of time, the bird moves a distance of to the right along the horizontal axis. Its vertical movement is controlled by the player. If the screen is tapped, the bird rises by a certain height , and you may tap multiple times within one unit of time with the effects adding up; if you do not tap, the bird falls by a certain height . The rise and fall can vary with the bird’s horizontal position.
If the bird’s height equals or it hits a pipe, the game fails. When the bird’s height is , it cannot rise further.
Now, please determine whether the game can be completed. If it can, output the minimum number of taps. Otherwise, output the maximum number of pipe gaps the bird can pass through.
Input Format
The first line contains integers , representing the length and height of the game interface and the number of pipes, respectively, separated by a single space.
The next lines each contain integers and , separated by a single space. For horizontal positions in order, denotes how much the bird will rise at the next position if the player taps at this position, and denotes how much the bird will fall at the next position if the player does not tap at this position.
Then follow lines, each containing integers , separated by single spaces. Each line describes one pipe, where is the pipe’s horizontal coordinate, is the lower boundary of the gap, and is the upper boundary of the gap (the input guarantees that all are distinct, but they are not guaranteed to be in sorted order).
Output Format
Output two lines.
The first line contains an integer. Output if the game can be successfully completed; otherwise, output .
The second line contains an integer. If the first line is , output the minimum number of taps required to complete the game. Otherwise, output the maximum number of pipe gaps the bird can pass through.
10 10 6
3 9
9 9
1 2
1 3
1 2
1 1
2 1
2 1
1 6
2 2
1 2 7
5 1 5
6 3 5
7 5 8
8 7 9
9 1 3
1
6
10 10 4
1 2
3 1
2 2
1 8
1 8
3 2
2 1
2 1
2 2
1 2
1 0 2
6 7 9
9 1 4
3 8 10
0
3
Hint
[Explanation for the sample input and output]
As shown in the figure below, the blue line is the bird’s flight path, and the red line represents the pipes.

Constraints
- For of the testdata: , , , and there exists an optimal solution where at most taps occur within any single unit of time.
- For of the testdata: , , and there exists an optimal solution where at most taps occur within any single unit of time.
- For of the testdata: , .
- For of the testdata: , , , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号