#P1437. [HNOI2004] 敲砖块
[HNOI2004] 敲砖块
Description
In a trough, there are layers of bricks. The top layer has bricks, and each lower layer has one fewer brick. Each brick has a score; knocking out a brick yields its score, as shown below:
14 15 4 3 23
33 33 76 2
2 13 11
22 23
31
If you want to knock out the -th brick in the -th layer, then if , you can knock it out directly; if , you must first knock out the -th and the -th bricks in layer .
You may knock out at most bricks. Find the maximum total score you can obtain.
Input Format
The first line contains two positive integers and ; then lines follow, describing the scores on these layers, where .
For of the testdata, it holds that , .
Output Format
Output a single line containing one positive integer, the maximum total value of the knocked-out bricks.
4 5
2 2 3 4
8 2 7
2 3
49
19
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号