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
#include <cstdio>
using namespace std;

const int maxn=2000;
int d[maxn][maxn];
int year[maxn][maxn];


int main() {
	int n, k, best_year=0;
	scanf("%d %d", &n, &k);
	for(int i=0;i<n;i++)
		for(int j=0;j<=i;j++) {
			scanf("%d", &year[i][j]);
			if(j==0 || j==i)
				d[i][j]=i+1;
			else
				d[i][j]=1+d[i-1][j-1]+d[i-1][j]-d[i-2][j-1];
			if(d[i][j]<=k && (best_year>year[i][j] || best_year==0))
				best_year=year[i][j];
		}
	printf("%d\n", best_year);

	return 0;
}