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
#include<iostream>
#include<vector>
using namespace std;

struct ind
{
    long long w;
    long long a;
};
 long long mini=9999999999999;
 ind tab[2000*(2001)/2+1];
int main ()
{
    ios_base::sync_with_stdio(0);
    long long t;
    t=1;
    for(long long q=0 ; q<t ; q++)
    {
    long long n,k;
    cin>>n>>k;
    long long x;
    long long y=1;
    for(long long i=0,j=0 ; i<n*(n+1)/2 ; i++)
    {
       cin>>x;
       if(i==0)tab[i].a=1;
       else if(j==0 || j==y-1) 
       {
            if(j==y-1)tab[i].a=tab[i-y].a+1;
            else if(j==0) tab[i].a=tab[i-y+1].a+1;
           tab[i].w=tab[i].a;
       }
       else 
       {
           tab[i].a=tab[i-y].a+tab[i-y].w;
           tab[i].w=tab[i-y].w;
       }
        if(x<mini && tab[i].a<=k)mini=x;
        j++;
        if(j==y)
        {
            y++;
            j=0;
        }

    }
   cout<<mini<<endl;
   mini=999999999999;
    }

    return 0;
}