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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<cstdio>

int n,k;
int ** A;
int ** cost;

int get(int ** T, int i, int j) {
  if (i >= 0 && j >= 0 && j <= i) {
    return T[i][j];
  }
  return 0;
}

void input() {
  scanf("%d %d", &n, &k);
  A = new int*[n];
  cost = new int*[n];
  for (int i = 0; i < n; ++i) {
    A[i] = new int[i + 1];
    cost[i] = new int[i + 1];
    for (int j = 0; j < i + 1; ++j) {
      scanf("%d", A[i] + j);
    }
  }
}

void compute_cost() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i + 1; ++j) {
      cost[i][j] = get(cost, i - 1, j - 1) + get(cost, i - 1, j) - get(cost, i - 2, j - 1) + 1;
    }
  }
}

void print(int ** T) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; ++j) {
      printf("%d ", T[i][j]);
    }
    printf("\n");
  }
}

int solve() {
  int best = 10000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (cost[i][j] <= k && A[i][j] < best) {
        best = A[i][j];
      }
    }
  }
  return best;
}

int main() {
  input();
  compute_cost();
  printf("%d\n", solve());
  return 0;
}