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
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int N, K;

int NthTriangle(const int n) {
  return n * (n+1) / 2;
}

int main() {
  cin >> N >> K;
  
  int ans = 9999;
  for (int y = 0; y < N; ++y) {
    for (int x = 0; x < y + 1; ++x) {
      int Y;
      cin >> Y;
      
      int required = NthTriangle(y + 1) - NthTriangle(x) - NthTriangle(y - x);
      if (required <= K)
        ans = min(ans, Y);
    }
  }
  
  cout << ans << endl;

  return 0;
}