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

int main() {
  int n;
  long long k;
  scanf("%d", &n); scanf("%lld", &k);
  int steps[n][n];

  //zbuduj tabele krokow
  for (int i = 0; i < n; i++) {
    steps[i][0] = i + 1;
    steps[i][i] = i + 1;
    for (int j = 0; j < i - 1; j++) {
      steps[i][j + 1] = steps[i - 1][j] + steps[i - 1][j + 1] + 1;
      if (i - 2 >= 0) {
        steps[i][j + 1] -= steps[i - 2][j];
      }
    }
  }
  
  // wypisz tabele kroków 
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < i + 1; j++) {
  //     printf("%d ", steps[i][j]);
  //   }
  //   printf("\n");
  // }

  int min_age = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i + 1; j++) {
      int age = 0;
      scanf("%d", &age);
      if ((i == 0) && (j == 0)) {
        min_age = age;
      } else {
        if (((long long int)steps[i][j] <= k) && (min_age > age)) {
          min_age = age;
        }

      }
    // printf("age %d -> min_age %d (steps: %d, k=%d)\n", age, min_age, steps[i][j], k);
    }
  }
  printf("%d\n", min_age);
}