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
#include <bits/stdc++.h>

using namespace std;
int n, k;
int sol = INT_MAX;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    int row = 1;
    for(int i = n; i >= 1; i--)
    {
        for(int j = 1; j <= row; j++)
        {
            int yr;
            cin>>yr;
            int un = (n * (n + 1) - (n - i + 1) * (n - i + 2)) / 2;
            int ls = j * (j - 1) / 2;
            int rs = (n - i + 1 - j) * (n - i + 2 - j) / 2;
            int rem = n * (n + 1) / 2 - un - ls - rs;
            if(rem <= k)
                sol = min(sol, yr);
        }
        row++;
    }
    cout<<sol;

    return 0;
}