1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cstdio>

using namespace std;

int n, k, a, result;
int T[2005];
int tab[2005][2005];

int main ()
{
	result = 10000;
	for (int i = 0; i < 2005; ++i) T[i] = (i + 1) * i / 2;
	for (int i = 0; i < 2005; ++i) for (int j = 0; j <= i; ++j) tab[i][j] = T[i + 1] - T[j] - T[i - j];
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++i) for (int j = 0; j <= i; ++j)
	{
		scanf("%d", &a);
		if (tab[i][j] <= k && a < result) result = a;
	}
	printf("%d\n", result);
	return 0;
}