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
#include <iostream>
#include <vector>

using namespace std;

long long min(long long a, long long b)
{
    if(a < b) return a;
    return b;
}

int main()
{
    long long n,k;

    cin >>n>>k;
    vector<vector<long long> > v(n, vector<long long>(n, 0));
    vector<vector<long long> > t(n, vector<long long>(n, 0));
    
    for(int i = 0; i < n; i++)
    {
        for(int j  = 0; j < i + 1; j++)
        {
            cin >> t[i][j];
        }
    }

    v[0][0] = 1;
    int res = t[0][0];
    //cout <<1<<endl;
    for(int i = 1;i<n;i++)
    {
        for(int j  = 0; j < i + 1;j++)
        {
            v[i][j] = v[i-1][j] + ((j > 0) ? v[i-1][j-1] : 0) + 1;
            if(i > 1 && j > 0) v[i][j] -= v[i-2][j-1];
            //cout <<v[i][j]<<" ";
            if (v[i][j] <= k)
            {
                res = min(res, t[i][j]);
            }
        }
        //cout <<endl;
    }
    cout <<res<<endl;
}