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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>

using namespace std;

struct butla{
    int rocznik, dp;
};

vector <butla> t[2001];

int main()
{
    int N, M;
    cin >> N >> M;
    int minRocznik = 2020;
    butla x;
    x.rocznik = 2020; x.dp = 0;
    t[0].push_back(x);
    t[0].push_back(x);
    for(int i = 1; i <= N; i++){
        butla x;
        x.dp = 0;
        x.rocznik = 2020;
        t[i].push_back(x);
        for(int j = 0; j < i; j++){
            butla x;
            cin >> x.rocznik;
            if(i == 1){
                x.dp = 1;
                minRocznik = x.rocznik;
            }
            else
                x.dp = 0;
            t[i].push_back(x);
        }
        x.dp = 0;
        x.rocznik = 2020;
        t[i].push_back(x);
    }
/*
    for(int i = 0; i <= N; i++){
        for(int j = 0; j < t[i].size(); j++){
            cout << "R = " << t[i][j].rocznik << ", d = " << t[i][j].dp << " | ";
        }
        cout << "\n";
    }
*/
    for(int i = 2; i <= N; i++){
        for(int j = 1; j < t[i].size() - 1; j++){
            //cout << "I = " << i << ", J = " << j << "\n";
            //cout << "t[i][j] = " << t[i - 1][j - 1].dp << " + " << t[i - 1][j].dp << " - " << t[i - 2][j - 1].dp << "\n";
            t[i][j].dp = t[i - 1][j - 1].dp + t[i - 1][j].dp - t[i - 2][j - 1].dp + 1;
            //cout << t[i][j].dp << "\n";
            if(t[i][j].dp <= M)
                minRocznik = min(minRocznik, t[i][j].rocznik);
        }
        //cout << "\n";
    }
    cout << minRocznik << "\n";
/*
    for(int i = 0; i <= N; i++){
        for(int j = 0; j < t[i].size(); j++){
            cout << "R = " << t[i][j].rocznik << ", d = " << t[i][j].dp << " | ";
        }
        cout << "\n";
    }
*/
}