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
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    int n, k;
    
    cin >> n >> k;

    vector<int> pv = vector<int>(n+2,-1);
    vector<int> cv = vector<int>(pv);

    pv[0] = pv[1] = 0;

    int minYear = 2019;

    for(int i = 0; i < n; i++){
        cv[0] = i % 2 == 0 ? pv[0]+1 : pv[1]*2 - pv[0] + 2;
// cout << cv[0];
        for(int j = 1; j < i+3; j++){
            cv[j] = (i+j) % 2 == 0 ? pv[j]+1 : pv[j+1]+pv[j-1]-pv[j]+2;
// cout << " " << cv[j];
        }
// cout << endl;

        for(int j = 0, cvix=i; j < i+1; j++, cvix-=2){
            int year;
            cin >> year;
            if(cv[abs(cvix)] <= k)
                minYear = min(minYear, year);
        }

        pv.swap(cv);
    }

    cout << minYear;

    return 0;
}