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

using ll = long long;
using ull = unsigned long long;

using namespace std;



ll caclVinesToRemove(vector<vector<ll>>& vines, ll row, ll vine)
{
    ll r= row, v =vine, x,y;

    x = row - (vine-1);
    y = vine;

    return x*y;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,k, year=0, forKing=numeric_limits<ll>::max(), vinesRemove = 0;

    cin>>n>>k;

    vector<vector<ll>> vines;
    vector<ll> oneRowVine;

    for(ll i=1;i<=n;i++)
    {
        oneRowVine.clear();
        for(ll j=0;j<i;j++)
        {
            cin>>year;
            oneRowVine.emplace_back(year);
        }
        vines.emplace_back(oneRowVine);
    }

    for(int i=0;i<n;i++)
    {
        for(ll j=0;j<=i;j++)
        {
            vinesRemove = caclVinesToRemove(vines,i+1,j+1);
            if(vinesRemove<=k)
            {
                forKing = min(forKing, vines[i][j]);
            }
        }
    }

    cout<<forKing<<'\n';
    return 0;
}