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

const int MAXN = 1005;
const int MAXK = MAXN * (MAXN - 1) / 2;
const int MAX_AGE = 2030;
int numbers[MAXN][MAXN];
int oldest[MAXK];
int main() {
	int n,k;
	cin >> n >> k;
	for (int i = 0; i < MAXK; i++) {
		oldest[i] = MAX_AGE;
	}
	numbers[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			int bottle;
			cin >> bottle;
			numbers[i][j] = 1;
			if (i - 1 >= 0 && j - 1 >= 0) {
				numbers[i][j] += numbers[i - 1][j - 1];
			}
			if (i - 1 >= 0 && j <= i - 1) {
				numbers[i][j] += numbers[i - 1][j];
			}
			if (i - 2 >= 0 && j - 1 >= 0) {
				numbers[i][j] -= numbers[i - 2][j - 1];
			}
			oldest[numbers[i][j]] = min(oldest[numbers[i][j]], bottle);
		}
	}
	for (int i = 1; i <= k; i++) {
		oldest[i] = min(oldest[i], oldest[i - 1]);
	}
	cout << oldest[k] << endl;
	return 0;
}