#P5989. [PA 2019] Wina

[PA 2019] Wina

Description

A number tower is formed by stacking n×(n+1)2\dfrac{n\times(n+1)}{2} numbers in nn rows.

Given kk, you need to take away exactly kk numbers so that the minimum value among the taken numbers is as small as possible. A number can be taken if and only if there is no number at its upper-left and upper-right positions, or those numbers have already been taken.

Input Format

The first line contains two positive integers n,kn, k. The next nn lines describe the tower. The ii-th line contains ii positive integers $a[i][1], a[i][2], ..., a[i][i](1\le a[i][j]\le 2019)$, representing the number in the ii-th row from top to bottom and the jj-th position from left to right.

Output Format

Output one integer: the minimum possible value of the minimum among the taken numbers.

5 7
1999
2019 2010
850 1500 1600
900 900 710 900
1000 800 600 800 1000
710

Hint

For 100%100\% of the testdata, 1n20001\le n\le 2000, 1kn×(n+1)21\le k\le \dfrac{n\times(n+1)}{2}.

Sample Explanation

Translated by ChatGPT 5