#P3800. Power 收集

    ID: 2740 远端评测题 2000ms 250MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp单调队列洛谷原创O2优化

Power 收集

Description

Treat the game screen as an NN-row by MM-column grid. There are P points on KK cells, and their values are val(i,j)\operatorname{val}(i,j).

Initially, Reimu may choose any cell in the first row to start. Each second, she must move down by exactly one row.

Reimu has a horizontal speed TT, allowing her each second to move left or right by at most TT columns, or not move horizontally at all, and she cannot reverse direction within a single move. Movement is considered instantaneous: she does not pass through intermediate cells en route and can only obtain the P point on the destination cell.

Compute the maximum possible total value of all P points she can obtain.

Input Format

The first line contains four integers, N,M,K,TN,M,K,T.

Each of the next KK lines contains three integers x,y,vx,y,v, indicating that there is a P point with val=v\operatorname{val}=v at row xx, column yy. It is guaranteed that there is at most 11 P point on any cell.

Output Format

Output a single integer, the maximum total value of P points Reimu can obtain.

3 3 4 1
1 1 3
1 2 1
2 2 3
3 3 3

9

Hint

For 40%40\% of the testdata, 1N,M,T,K2001 \le N,M,T,K \le 200.

For 100%100\% of the testdata, 1N,M,T,K40001 \le N,M,T,K \le 4000, 0v1000 \le v \le 100, and N,M,K,TN,M,K,T are all integers.

by-szc

Translated by ChatGPT 5