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
#include<stdio.h>
#include<vector>


int main()
{
	
	int n = 10, k = 5, year, min_year = 2020;

	scanf("%d %d", &n, &k);

	std::vector<std::vector<int>> tab;

	for(int i = 0; i<n; i++)
	{
		std::vector<int> tab2;
		tab.push_back(tab2);
		for(int j = 0; j<=i; j++)
		{
			int val;
			if(i== 0 && j ==0)
			{
				val = 1;
			} else if(j == 0)
			{
				val = tab[i-1][j] + 1;
			}
			else if(j == i)
			{
				val = tab[i-1][j -1] + 1;
			} 
			else 
			{
				val = tab[i-1][j] +  tab[i-1][j -1] - tab[i-2][j -1] + 1;
			}

			tab[i].push_back(val);

			scanf("%d", &year);
			if(val <= k && year <= min_year)
			{
				min_year = year;
			}
		}
	}

	printf("%d", min_year);

	return 0;
}