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
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector < vector <int> > A(n+1), D(n+1);
    for (int i = 1; i <= n; i++) {
        A[i].resize(i);
        D[i].resize(i);
        for (int j = 0; j < i; j++) {
            cin >> A[i][j];
        }
        D[i][0] = D[i][i-1] = i;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < i-1; j++) {
            D[i][j] = 1 + D[i-1][j-1] + D[i-1][j] - D[i-2][j-1];
        }
    }
    int ans = A[1][0];
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            if (D[i][j] <= k) {
                ans = min(ans, A[i][j]);
            }
        }
    }
    cout << ans <<endl;
    return 0;
}