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
#include <algorithm>
#include <iostream>
#include <vector>


constexpr int depth(const int i, const int j)
{
  return (i - j + 1) * (j + 1);
}


constexpr int position(const int i, const int j)
{
  return i * (i + 1) / 2 + j;
}


int main()
{
  std::ios::sync_with_stdio(false);

  int n, k;
  std::cin >> n >> k;
  int num_bottles = n * (n + 1) / 2;

  std::vector<int> wines(num_bottles);
  for (int i = 0; i < num_bottles; ++i) {
    std::cin >> wines[i];
  }

  int oldest = wines[0];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (depth(i, j) <= k) {
        oldest = std::min(oldest, wines[position(i, j)]);
      }
    }
  }

  std::cout << oldest << std::endl;
  return 0;
}