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
#include <iostream>

using namespace std;
const int MAX_N = 2002;
int tab[MAX_N][MAX_N], n, k;
int minYear=10000, curYear, dist;

int inline val(int row, int col) {
	if(row < col || col<0)
		return 0;
	else
		return tab[row][col];
}

int inline solve(int row, int col) {
	return val(row-1, col-1) + val(row-1, col) - val(row-2, col-1) + 1;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> k;
	tab[0][0] = 1;
	for(int row=0; row<n; ++row)
		for(int col=0; col<=row; ++col) {
			cin>>curYear;
			tab[row][col] = dist = solve(row, col);
			if(dist <= k && curYear < minYear)
				minYear = curYear;
		}
	cout << minYear;
	return 0;
}