#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 HH. Everyone can ski down from the peak to the base using the centroid path. To increase the difficulties, NN 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 ii-th gate is located at height YiY_i and XiX_i units to the right of the centroid path. If XiX_i is negative then it is to the left of the centroid path. Passing through the ii-th gate gives SiS_i 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 EiE_i (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 ii-th gate to the jj-th gate if max(XjXi,YiYj)Ei\max(|X_j - X_i|, Y_i - Y_j) \leq E_i and YiYjY_i \geq Y_j. 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 NN and HH. The next NN lines contain 4 integers each. The (i+1)(i+1)-th line represents Xi,Yi,Si,EiX_i, Y_i, S_i, E_i.

输出格式

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.

  1. Top (0,5)\rightarrow (0, 5) \rightarrow Bottom, Score: 5
  2. Top (3,4)(1,1)\rightarrow (3, 4) \rightarrow (1, 1) \rightarrow Bottom, Score: 4+4=84 + 4 = 8
  3. Top $\rightarrow (-2, 3) \rightarrow (-1, 2) \rightarrow$ Bottom, Score: 3+3=63 + 3 = 6

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 NN Others
1 7 1N3001 \leq N \leq 300 Ei=200000E_i = 200000 for all ii
2 8 Xi=0X_i = 0 for all ii, Ei=EjE_i = E_j for all i,ji, j
3 11 YiYjY_i \neq Y_j for all iji \neq j
4 13 1N20001 \leq N \leq 2000
5 15 1N500001 \leq N \leq 50000 YiYjY_i \neq Y_j for all iji \neq j, Ei=EjE_i = E_j for all i,ji, j
6 13 Ei=EjE_i = E_j for all i,ji, j
7 16 YiYjY_i \neq Y_j for all iji \neq j
8 17 1N2000001 \leq N \leq 200000

For all test cases, 50000Xi50000-50000 \leq X_i \leq 50000, 1YiH2000001 \leq Y_i \leq H \leq 200000, 1Si1061 \leq S_i \leq 10^6, 1Ei2000001 \leq E_i \leq 200000