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
#include <bits/stdc++.h>
using namespace std;
#define mk make_pair
#define fi first
#define sz(x) x.size()
#define se second
#define pb push_back
#define VAR(v) #v << " " << v << " "
#define debug if(0)
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = (int)1e6 + 9;
const int INF = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
int ans[2009][2009];

int f(int i, int j)
{
    if(i < 0 || j < 0 || i > j)
        return 0;
    return ans[i][j];
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    debug; else cin.tie(NULL), cout.tie(NULL);
    int n, k; cin>>n>>k;
    int ret = INF;
    for(int j = 0; j < n; j++)
    {
        for(int i = 0; i <= j; i++)
        {
            ans[i][j] = f(i-1, j-1) + f(i, j-1) - f(i-1, j - 2) + 1;
            int x; cin>>x;
            if(ans[i][j] <= k)
                ret = min(ret, x);
        }
        debug cout << endl;
    }
    cout<<ret;
    return 0;
}