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
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>


using namespace std;


const int INF = 1 << 30;


int solve(int n, int k, vector <vector<int>> &tab) {
    vector <vector<int>> above(n);

    for (int i = 0; i < n; i++) {
        above[i].resize(i + 1, 1);

        for (int j = 0; j <= i; j++) {
            if (i >= 1 && j < i) {
                above[i][j] += above[i-1][j];
            }

            if (i >= 1 && j >= 1) {
                above[i][j] += above[i-1][j-1];
            }

            if (i >= 2 && j >= 1 && j < i) {
                above[i][j] -= above[i-2][j-1];
            }
        }
    }

    int ans = INF;

    for (int i = 0; i < n; i++) for (int j = 0; j <= i; j++) {
        if (above[i][j] <= k) {
            ans = min(ans, tab[i][j]);
        }
    }

    return ans;
}


int main() {
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector <vector<int>> tab(n);

    for (int i = 0; i < n; i++) {
        tab[i].resize(i + 1);

        for (int j = 0; j <= i; j++) {
            cin >> tab[i][j];
        }
    }

    cout << solve(n, k, tab);

    return 0;
}