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
#include <bits/stdc++.h>


using namespace std;
int t[3000][3000];
int cost[3000][3000];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			scanf("%d", &t[i][j]);
		}
	}
	cost[1][1] = 1;
	cost[2][1] = 2;
	cost[2][2] = 2;
	for (int i = 3; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			cost[i][j] = cost[i-1][j] + cost[i-1][j-1] - cost[i-2][j-1] + 1;
		}
	}
	int best = 1e9;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			if (cost[i][j] <= k) best = min(best, t[i][j]);
		}
	}
	printf("%d\n", best);

	return 0;
}