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

using namespace std;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int max_y, allowable_to_take;

    cin >> max_y >> allowable_to_take;

    int best_year = std::numeric_limits<int>::max();

    for (int y = 1; y <= max_y; ++y) {
        for (int x = 1; x <= y; ++x) {
            int now;
            cin >> now;

            int steps_to_take =
                    y * (y + 1) / 2 - (y - x) * (y - x + 1) / 2 - (x - 1) * x / 2;

            //            cout << now << " (" << x << ", " << y << "): " << steps_to_take << endl;

            if (steps_to_take <= allowable_to_take) {
                best_year = std::min(best_year, now);
            }
        }
    }

    cout << best_year << endl;
}