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
#include <iostream>

using namespace std;
int n,k;

int najstar=0,lin=1,iter,buf;
int **tab;
bool zero;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    cin>>k;
    tab = new int *[n];
    for(int i=0; i<n; i++) tab[i] = new int [i+1];
    for(int i=0; i<n; i++)
        for(int j=0; j<=i; j++) cin>>tab[i][j];
    najstar = tab[0][0];
    k--;
    while(k--)
    {
        zero = true;
        buf = tab[lin-1][0];
        iter = 0;
        for(int i=0; i<lin; i++)
            if(tab[lin-1][i]<buf && tab[lin-1][i]!=0){
                zero = false;
                buf = tab[lin-1][i];
                iter = i;
            }
        tab[lin-1][iter] = 0;
        if(buf < najstar)najstar = buf;
        if(zero)lin++;
    }
    cout<<najstar;
    return 0;
}