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
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    int n, k, el, mini = 2100;
    cin >> n >> k; 
    vector<int> bottles_above[n];
    bottles_above[0].pb(1);
    if (n>1) {
        bottles_above[1].pb(2);
        bottles_above[1].pb(2);
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<i+1; j++) {
            cin >> el;
            if (i > 1) {
                if (j > 0 && j < i) {
                    bottles_above[i].pb(bottles_above[i-1][j-1] + bottles_above[i-1][j] - bottles_above[i-2][j-1] + 1);
                } else {
                    bottles_above[i].pb(bottles_above[i-1][0] + 1);
                }
            }
            if (bottles_above[i][j] <= k) mini = min(mini, el);
        }
    }
    cout << mini << endl;
    return 0;
}