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 <algorithm>
#include <cstdio>

using namespace std;

const int MAXN = 2000;

int d[MAXN + 1][MAXN + 1];

int f(int i, int j) {
  if (i < 0 || j < 0 || j > i) {
    return 0;
  }
  return d[i][j];
}

int main() {
  int n, k;
  int res = 2020;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      int x;
      scanf("%d", &x);
      d[i][j] = f(i - 1, j - 1) + f(i - 1, j) - f(i - 2, j - 1) + 1;
      if (d[i][j] <= k) {
        res = min(res, x);
      }
    }
  }
  printf("%d\n", res);
}