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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
#define rok first
#define dp second
using namespace std;

pair < int , int > butelka[2000][2000];
pair <int , int > inf[2001000];
int n,k,pom,l;

bool sortme(pair <int,int> a, pair <int,int> b)
{
    if(butelka[a.first][a.second].rok <= butelka[b.first][b.second].rok)
        return 1;
    return 0;
}


int main()
{
    cin >> n >> k;
    cin >> pom;
    butelka[1][1].rok=pom;
    butelka[1][1].dp=1;
    cin >> pom;
    butelka[2][1].rok=pom;
    butelka[2][1].dp=2;
    cin >> pom;
    butelka[2][2].rok=pom;
    butelka[2][2].dp=2;
    l=3;
    inf[0]=make_pair(1,1);
    inf[1]=make_pair(2,1);
    inf[2]=make_pair(2,2);
    for (int i=3; i<=n; i++)
        for (int j=1; j<=i; j++)
        {
            cin >> pom;
            butelka[i][j].rok=pom;
            inf[l].first=i;
            inf[l].second=j;
            l++;

            if(j==1 || j==i)
            {
                butelka[i][j].dp=i;
            }

            butelka[i][j].dp= (butelka[i-1][j-1].dp) + (butelka[i-1][j].dp)+ 1;
            butelka[i][j].dp-= butelka[i-2][j-1].dp;
        }

    sort(inf,inf+(n*(n+1)/2),sortme);

    for (int i=0; 1; i++)
    {
        if (butelka[inf[i].first][inf[i].second].dp<=k)
        {
            cout << butelka[inf[i].first][inf[i].second].rok;
            return 0;
        }
    }


}