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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define MAXN 2001

using namespace std;

vi V[MAXN];

bool valid(int x, int y) {
	return (y >= 0 && x >= 0 && x <= y);
}

int cost(int x, int y) {
    int lefta_x, righta_x, a_y, commona_x, commona_y;

    lefta_x = x - 1;
    righta_x = x;
    a_y = y - 1;

    commona_x = lefta_x;
    commona_y = a_y - 1;

	int res = 1;
	// cout<<"---"<<endl;
	// cout<<x<<" "<<y<<endl;
	// cout<<" "<<valid(lefta_x, a_y)<<endl;
	// cout<<" "<<valid(righta_x, a_y)<<endl;
	// cout<<" "<<valid(commona_x, commona_y)<<endl;

	if(valid(lefta_x, a_y))
		res += V[a_y][lefta_x];
	if(valid(righta_x, a_y))
		res += V[a_y][righta_x];
	if(valid(commona_x, commona_y))
		res -= V[commona_y][commona_x];
	return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;

    int res = 10000;
    int year;
    int x, y;
    for (int i = 0; i < n; i++) {
        V[i].resize(i + 1);
        for (int j = 0; j < V[i].size(); j++) {
            cin >> year;

			V[i][j] = cost(j, i);
			if(V[i][j] <= k)
				res = min(res, year);
        }
    }

	// for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < V[i].size(); j++) {
    //        cout<<V[i][j]<<" ";
    //     }
	// 	cout<<endl;
    // }

	cout<<res<<endl;

    return 0;
}