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
#include<bits/stdc++.h>
    using namespace std;
    pair<int,int>piramida[5000000];
    #define st first
    #define nd second
    int main(){
        int n,k;
        cin>>n>>k;
        int indeks=n*(n+1)/2;
        int c=2;
        int x;
        cin>>x;
        piramida[1]=make_pair(x,1);
        if(k==1){
            cout<<piramida[1].st;
            return 0;
        }
        for(int i=1;i<indeks;i=i+c-1){
           for(int a=i+1;a<=i+c;a++){
                if(a==i+1){
                    cin>>x;
                    piramida[a]=make_pair(x,piramida[a-c+1].nd+1);
                }
                if(a==i+c){
                    cin>>x;
                    piramida[a]=make_pair(x,piramida[a-c].nd+1);
                }
                if(a>i+1&&a<i+c){
                    cin>>x;
                    piramida[a]=make_pair(x,piramida[a-c].nd+piramida[a-c+1].nd-piramida[a-c-c+2].nd+1);
                }
           }
           c++;
        }
        int wynik=2020;
        for(int i=1;i<indeks;i++){
            if(piramida[i].nd<=k&&piramida[i].st<wynik){
                wynik=piramida[i].st;
            }
        }
        cout<<wynik;
    return 0;
    }