1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdio>
#include <algorithm>

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

int main() {
    int N, K;
    int result = 1000000;
    scanf("%d %d",&N,&K);

    for (int level=1; level<=N; ++level) {
        for (int pos=1; pos<=level; ++pos) {
            int val, toRemove;
            scanf("%d",&val);
            toRemove = psize(level) - psize(level-pos) - psize(pos-1);
            if (toRemove <= K) result=std::min(result, val);
        }
    }

    printf("%d\n", result);
    return 0;
}