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
#include <iostream>
#define MAX_DLUGOSC 100
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n;
  int k;
  int year;
  int min_year = 1000000;
  
  cin >> n;
  cin >> k;
  
  for (int i=1; i<n+1; i++) {
      for (int j=1; j<i+1; j++) {
          cin >> year;
          
          int stability_index = (i*(i+1))/2 - ((j-1)*j)/2 - ((i-j)*(i-j+1))/2;
          if (stability_index <= k && year < min_year) {
              min_year = year;
          }
      }
  }
  
  cout << min_year << "\n";
  
  return 0;
}