#P1544. 三倍经验

三倍经验

Description

A number pyramid has nn rows of integers. The ii-th row (1in1 \le i \le n) has ii numbers. One example is as follows.

        7
      3   9
    8   1   0
  2   7   4   4 
4   5   2   6   5

Now you start at the top of the pyramid (the first row) and want to reach the bottom (the nn-th row). At each step, you can move to the number down-left or down-right of your current position. Also, as a powerful kid, you may choose at most kk numbers in the pyramid and make them 33 times their original value.

You will collect all numbers along your path. Your final score is the sum of the collected numbers. Find the maximum possible score.

Input Format

The first line contains two integers n,kn,k, the number of rows in the number pyramid and the maximum count of numbers that can be multiplied by 33.
Then follow nn lines. The ii-th of them contains ii space-separated integers, which are the numbers in the ii-th row of the pyramid: ai,1,ai,2,ai,3...ai,ia_{i,1},a_{i,2},a_{i,3}...a_{i,i}.

Output Format

Output a single integer, the maximum score.

5 3
7
3 9
8 1 0
2 7 4 4
4 5 2 6 5
75

Hint

Constraints:
For 30%30\% of the testdata, kn6k \le n \le 6, and for any 1in1 \le i \le n, 1ji1 \le j \le i it holds that 0ai,j1000 \le a_{i,j} \le 100.
For 100%100\% of the testdata, 1n1001 \le n \le 100, 0kn(n+1)20 \le k \le \dfrac{n(n+1)}{2}, and for any 1in1 \le i \le n, 1ji1 \le j \le i it holds that ai,j109|a_{i,j}| \le 10^9.

Translated by ChatGPT 5