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

using namespace std;

const int lim = 2009;
int t[lim][lim],n,k,w;

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