#P1941. [NOIP 2014 提高组] 飞扬的小鸟

    ID: 889 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2014NOIp 提高组枚举,暴力背包

[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 nn and height mm, containing kk 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 11 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 xx, 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 yy. The rise xx and fall yy can vary with the bird’s horizontal position.

If the bird’s height equals 00 or it hits a pipe, the game fails. When the bird’s height is mm, 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 33 integers n,m,kn, m, k, representing the length and height of the game interface and the number of pipes, respectively, separated by a single space.

The next nn lines each contain 22 integers xx and yy, separated by a single space. For horizontal positions 0n10 \sim n - 1 in order, xx denotes how much the bird will rise at the next position if the player taps at this position, and yy denotes how much the bird will fall at the next position if the player does not tap at this position.

Then follow kk lines, each containing 33 integers p,l,hp, l, h, separated by single spaces. Each line describes one pipe, where pp is the pipe’s horizontal coordinate, ll is the lower boundary of the gap, and hh is the upper boundary of the gap (the input guarantees that all pp are distinct, but they are not guaranteed to be in sorted order).

Output Format

Output two lines.

The first line contains an integer. Output 11 if the game can be successfully completed; otherwise, output 00.

The second line contains an integer. If the first line is 11, 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 30%30\% of the testdata: 5n105 \leq n \leq 10, 5m105 \leq m \leq 10, k=0k = 0, and there exists an optimal solution where at most 33 taps occur within any single unit of time.
  • For 50%50\% of the testdata: 5n205 \leq n \leq 20, 5m105 \leq m \leq 10, and there exists an optimal solution where at most 33 taps occur within any single unit of time.
  • For 70%70\% of the testdata: 5n10005 \leq n \leq 1000, 5m1005 \leq m \leq 100.
  • For 100%100\% of the testdata: 5n100005 \leq n \leq 10000, 5m10005 \leq m \leq 1000, 0k<n0 \leq k < n, 0<x,y<m0 < x, y < m, 0<p<n0 < p < n, 0l<hm0 \leq l < h \leq m, l+1<hl + 1 < h.

Translated by ChatGPT 5