QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 80

#16171. Brick Breaking

Statistiques

There are $n$ layers of bricks placed in a groove. The top layer has $n$ bricks, the second layer has $n-1$ bricks, ..., and the bottom layer has only one brick. The bricks in the $i$-th layer are numbered $1, 2, \dots, n-i+1$ from left to right. The $j$-th brick in the $i$-th layer has a value $a[i, j]$ ($a[i, j] \le 50$). Below is an example of a 5-layer brick stack:

To knock out the $j$-th brick in the $i$-th layer, if $i=1$, you can knock it out directly. If $i>1$, you must first knock out the $j$-th and $(j+1)$-th bricks in the $(i-1)$-th layer.

Your task is to knock out $m$ ($m \le 500$) bricks from a stack of $n$ ($n \le 50$) layers such that the total value of the knocked-out bricks is maximized.

Input

The first line contains two positive integers $n$ and $m$. Each of the following $n$ lines contains the values for the bricks in each layer. Specifically, the $i$-th line (where $1 \le i \le n$) contains $n-i+1$ integers, representing $a[i, 1], a[i, 2], \dots, a[i, n-i+1]$.

Output

Output a single positive integer representing the maximum total value of the knocked-out bricks.

Examples

Input 1

4 5
2 2 3 4
8 2 7
2 3
49

Output 1

19

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.