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 N 2002
#define MAX 2020
#define LL long long
using namespace std;
LL t[2][N];
LL n, k, a, mn = MAX;
bool in;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    mn = MAX;
    for (int i = 1; i <= n; ++i)
    {
        in = (i % 2);
        for (int j = 1; j <= i; ++j)
        {
            cin >> a;
            t[in][j] = j;
            if (j != i)
                t[in][j] += t[!in][j];
            if (a < mn && t[in][j] <= k)
                mn = a;
        }
    }
    cout << mn << "\n";
    return 0;
}