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
36
37
#include <iostream>
using namespace std;

const int NN = 2007;

int n, k, year, answer;
int depth[NN][NN];

int get_depth(int row, int j) {
  if (row <= 0)
    return 0;
  if (j <= 0)
    return 0;
  if (j > row)
    return 0;
  return depth[row][j];
}

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

  cin >> n >> k;
  answer = 2019;

  for (int row=1; row<=n; row++)
    for (int j=1; j<=row; j++) {
      cin >> year;
      depth[row][j] = get_depth(row-1, j-1) + get_depth(row-1, j) - get_depth(row-2, j-1) + 1;
      if (depth[row][j] <= k)
        answer = min(answer, year);
    };

  cout << answer;

  return 0;
}