#P13649. [NOISG 2016] Panda Ski
[NOISG 2016] Panda Ski
题目描述
The Winter Olympics is coming and Mr. Panda has been training very hard to take part in the skiing event. This event takes place on the mountain Mt. Rar which is of height . Everyone can ski down from the peak to the base using the centroid path. To increase the difficulties, gates, each associated with a score, are placed at various heights and either to the left or to the right of the centroid path. The objective is to ski down from the peak to the base and achieve score by passing through some subset of gates.
The -th gate is located at height and units to the right of the centroid path. If is negative then it is to the left of the centroid path. Passing through the -th gate gives points and you can pass through the same gate multiple times but you only get points for the first time you pass through a gate. No gate is at the same point.
Mr. Panda wants to maximize his score. Moreover, Mr. Panda understands he is not a good skier and he will fail to visit some gates. To avoid embarrassing himself, Mr. Panda analyses the gates and gives each gate an easiness score (high score is easier) based on the angle of the slope, the amount of snow, etc.
Precisely, Mr. Panda calculated that he can move from the -th gate to the -th gate if and . Also, it is possible to get from the peak to any gate and from any gate to the base of the mountain.
Mr. Panda is overwhelmed by the number of possible paths moving down the mountain and he needs your help to find the path that will give him the maximum score.
输入格式
Your program must read from standard input. The first line of input contains two positive integers and . The next lines contain 4 integers each. The -th line represents .
输出格式
You program must output one line with a single integer to the standard output, which is the maximum score Mr. Panda can attain.
5 5
0 5 5 1
3 4 4 3
-2 3 3 2
1 1 4 4
-1 2 3 1
8
提示
Explanation
There are only 3 possible paths Mr. Panda can take.
- Top Bottom, Score: 5
- Top Bottom, Score:
- Top $\rightarrow (-2, 3) \rightarrow (-1, 2) \rightarrow$ Bottom, Score:
So the best score is 8.
Subtasks
The maximum execution time on each instance is 1.0s. Your program will be tested on sets of input instances as follows:
Subtask | Marks | Others | |
---|---|---|---|
1 | 7 | for all | |
2 | 8 | for all , for all | |
3 | 11 | for all | |
4 | 13 | ||
5 | 15 | for all , for all | |
6 | 13 | for all | |
7 | 16 | for all | |
8 | 17 |
For all test cases, , , ,