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

const int ac = 2e3 + 6, mod = 1e9 + 7;
int A[ac][ac];
int C[ac][ac];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i + 1; j++)
			cin >> A[i][j];
	C[0][0] = 1;
	int m = A[0][0];
	for (int i = 1; i < n; i++)
		for (int j = 0; j < i + 1; j++)
		{
			C[i][j] += C[i - 1][j];
			if (j) C[i][j] += C[i - 1][j - 1];
			if (i >= 2 && j) C[i][j] -= C[i - 2][j - 1];
			C[i][j]++;
			if (C[i][j] <= k) m = min(m, A[i][j]);
		}
	cout << m << '\n';
}