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

using namespace std;

typedef vector<int> vi_t;
typedef vector<vi_t> vvi_t;

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

    int n, k, best, akt;
    int rakt = 0, rprev = 2, rprev2 = 1;
    cin >> n >> k;
    n = min(k, n);
    vvi_t rows = vvi_t(3, vi_t(n + 3, 0));
    cin >> best;
    rows[rprev][1] = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < i + 2; ++j) {
            cin >> akt;
            rows[rakt][j] =
                1 + rows[rprev][j - 1] + rows[rprev][j] - rows[rprev2][j - 1];
            if (rows[rakt][j] <= k) {
                best = min(best, akt);
            }
        }
        rakt = (rakt + 1) % 3;
        rprev = (rprev + 1) % 3;
        rprev2 = (rprev2 + 1) % 3;
    }
    cout << best << endl;
    return 0;
}