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
// Patryk Kisielewski - Wina [B] - wina.cpp
#include <cstdio>

int main(){
    int n, k;
    int sum;
    int a;
    int min;

    while(scanf("%d%d", &n, &k) != EOF){

        sum = 0;
        min = 2019;
        
        for(int i = 1; i <= n; ++i){
            sum += i;

            for(int j = 0; j < i; ++j){
                scanf("%d", &a);
                if(sum - (j*(j+1) + (i-j)*(i-j-1)) / 2 <= k){
                    if(a < min)
                        min = a;
                }
            }
        }

        printf("%d\n", min);
    }

    return 0;
}