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<bits/stdc++.h>
using namespace std;

int n,K,a[2001005],pr[2001005],lr[2001005],t[2001006],p = 1,k = 1,w;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin>>n>>K;
    for(int i = 1;i < n; ++i)
    {
        int l = (i * (i + 1)) / 2 + 1,r = l + 1;
        for(int j = p;j <= k; ++j) 
        {
            pr[l] = lr[r] = j;
            l = r;
            r++;
        }
        p = (i * (i + 1)) / 2 + 1,k = p + i;
    }
    cin>>a[1];
    t[1] = 1;
    w = a[1];
    int x = (n * (n + 1)) / 2;
    for(int i = 2;i <= x; ++i)
    {
        cin>>a[i];
        if(!lr[i] || !pr[i])
            t[i] = max(t[lr[i]],t[pr[i]]) + 1;
        else
            t[i] = t[lr[i]] + t[pr[i]] - t[pr[lr[i]]] + 1;
        if(t[i] <= K) w = min(w,a[i]);
    }
    cout<<w;
    return 0;
}