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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    vvi a(n);

    for (int i = 0; i < n; i++) {
        a[i] = vi(i + 1);
        for (int& x : a[i])
            cin >> x;
    }

    vvi c;
    c.push_back(vi(1, 1));
    c.push_back(vi(2, 2));
    c.resize(n);

    for (int i = 2; i < n; i++) {
        c[i] = vi(i + 1, 1);

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

    int z = a[0][0];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            if (c[i][j] <= k)
                z = min(z, a[i][j]);
        }
    }

    cout << z << "\n";

    return 0;
}