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

const int M = 4 * 1e6 + 9;
int n,k,num,res = 2020;
int dp[M];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin.tie(0);
    
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        for(int j=1,a; j<=i; j++){
            cin >> a;
            num++;
            if(j == 1)
                dp[num] = dp[num-i+1] + 1;
            else if(j == i)
                dp[num] = dp[num-i] + 1;
            else
                dp[num] = dp[num-i+1] + dp[num-i] - dp[num-2*(i-1)] + 1;
            if(dp[num] <= k)
                res = min(res,a);
        }
    }
    cout<<res<<endl;
    return 0;
}