1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, n) for(auto &i : n)
#define SZ(x) (int)(x).size()
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

int dp[2005][2005];
int A[2005][2005];

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	int n, k;
	std::cin >> n >> k;
	FOR(i, n){
		FOR(j, i+1){
			std::cin >> A[i][j];
		}
	}
	dp[0][0] = 1;
	int ans = A[0][0];
	REP(i, 1, n){
		FOR(j, i+1){
			dp[i][j] = 1 + (j == 0 ? 0 : dp[i-1][j-1])+(j == i ? 0 : dp[i-1][j]);
			if(j != 0 && j != i) dp[i][j] -= dp[i-2][j-1];
			if(dp[i][j] <= k) ans = std::min(ans, A[i][j]);
		}
	}
	std::cout << ans;
	return 0;
}