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

using namespace std;

int getLastInLayer(int n){
    return (n * (n + 1) / 2);
}

int wymagane(int val){
    int layer = round(sqrt(2 * val));

    return (val - getLastInLayer(layer - 1)) * (getLastInLayer(layer) - val + 1);
}

int main()
{
    int n, k;
    cin >> n >> k;

    int oldestYet = 2020;

    for(int i = 1; i <= getLastInLayer(n); i++){
        int a;
        scanf("%d", &a);

        if(a < oldestYet){
            if(wymagane(i) <= k)
                oldestYet = a;
        }
    }

    cout << oldestYet << endl;

    return 0;
}