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
/// Radoslaw Mysliwiec 2019
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB emplace_back
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int,int>;
using pll = pair<ll,ll>;

int tab[4100][4010];
int pref[4100][4010];
int n, k, a;
int res = 9999999;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k;
    for (int i=1; i<=n; ++i){
        for (int j=1; j<=i; ++j){
            cin >> tab[j][i-j+1];
        }
    }

    for (int i=1; i<=n; ++i){
        for (int j=1; j<=n; ++j){
            if(tab[i][j]) {
                pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + 1;
                if (pref[i][j] <= k){
                    res = min(res,tab[i][j]);
                }
            }
        }
    }
    cout << res << endl;
}