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
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

int main() {
	int height, needed, min_year = 2020;
	std::scanf("%d %d", &height, &needed);

	for (int row = 1; row <= height; row++) {
		for (int col = 1; col <= row; col++) {
			int year;
			std::scanf("%d", &year);

			int l = col - 1;
			int r = row - col;
			int left = l * (l + 1) / 2;
			int right = r * (r + 1) / 2;
			int total = row * (row + 1) / 2;
			int taken = total - left - right;

			if (taken <= needed && year < min_year) {
				min_year = year;
			}
		}
	}

	std::printf("%d", min_year);
	return 0;
}