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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector <int> dp((n*(n+1)) / 2, 1);
	
	int ans = INT_MAX;
	
	int size = 1, x = 1;
	for(int i = 0; i < (n*(n+1))/2; ++i) {
		int year;
		cin >> year;
		
		if(dp[i] <= k)
			ans = min(ans, year);
		
		if(i == x) {
			size++;
			x += size;
		}	
		
		if(i+2*(size+1) < (n*(n+1)) / 2)
			dp[i+2*(size+1)] -= dp[i];
		if(i + size < (n*(n+1)) / 2) 
			dp[i+size] += dp[i];
		if(i+size+1 < (n*(n+1)) / 2)
			dp[i+size+1] += dp[i];
	}
	
	cout << ans;
}