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

using namespace std;

int n,k;
int res=2019;

int suma(int lo,int hi)
{
    if(lo>hi) return 0;
    int ans=(lo+hi);
    ans*=(hi-lo+1);
    ans/=2;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            int x; cin>>x;
            int ile=suma(i+1,n);
            ile+=suma(1,j-1);
            ile+=suma(1,i-j);
            if(suma(1,n)-ile<=k) res=min(res,x);
        }
    }
    cout<<res;
    return 0;
}