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
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>
#include <climits>
#include <cstdio>

using namespace std;

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    vector<vector<int>> piramida(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<(i+1);j++) {
            int temp;
            scanf("%d", &temp);
            piramida[i].push_back(temp);
        }
    }
    vector<int> pir(n);
    pir[0]=0;
    pir[1]=1;
    for(int i=2; i<(n+1); i++) {
        pir[i]=pir[i-1]+i;
    }

    //vector<vector<int>> to_drop(n);
    int min_so_far = INT_MAX;

    for(int i=0;i<n;i++){
        for(int j=0;j<(i+1);j++) {
            int left = j;
            int right = i+1-(j+1);
            int num = pir[i+1]-pir[left]-pir[right];
            //printf("num  %d ", num);
            //printf("indx: l:%d r:%d val level:%d l:%d r:%d\n", left, right, pir[i+1], pir[left], pir[right]);
            //to_drop[i].push_back(num);
            //printf("%d for i=%d j=%d\n", to_drop[i][j], i, j);
            if(num <= k) {
                if(piramida[i][j] <= min_so_far) min_so_far = piramida[i][j];
            }
        }
    }
    printf("%d", min_so_far);

    return 0;
}

//Autor: Helena Borak-Wejster