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
#include <iostream>

using namespace std;

#define countPyramidBottles(x) ((x)*(x+1) >> 1)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, k;
	cin >> n >> k;

	int earliestYear = 2020;

	for (int row = 0; row < n; ++row) {
		for (int col = 0; col <= row; ++col) {
			int year;
			cin >> year;

			if (countPyramidBottles(row + 1) - countPyramidBottles(col) - countPyramidBottles(row - col) <= k) {
				if (year < earliestYear) earliestYear = year;
			}

		}
	}

	cout << earliestYear;
}