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
#include <iostream>
using namespace std;

#define MAX 2020

int wina[MAX][MAX];

int main()
{
    int n, k, x = 0, y = 0, mx = MAX;
    cin >> n >> k;
    for(int i = 0; i < n * (n + 1) / 2; ++i) {
        cin >> wina[x][y];
        int stacked = (x+1)*(x+2)/2 - y * (y + 1) / 2 - (x-y) * (x-y+1) / 2;
        if(stacked <= k && wina[x][y] <= mx) {
            mx = wina[x][y];
        }
        if(x == y) {
            ++x;
            y = 0;
        } else {
            ++y;
        }
    }
    cout << mx << endl;
    return 0;
}