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
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
struct Butla
{
    short rok;
    uint64_t zasieg;
    Butla(int rrok)
    {
        rok=rrok;
    }
};
void UstalZasieg(vector< vector<Butla> > &v)
{
    unsigned int it = 1;
    for(unsigned int i=0;i<v.size();i++)
    {
        for(unsigned int j=0;j<v[i].size();j++)
        {
            double t = floor((double)(-1+sqrt(8*it-7))/2);
            uint64_t ans = ((t*t+3*t+4)/2-it)*(it-(t*(t+1)/2));
            v[i][j].zasieg = ans;
            it++;
        }
    }
}
int main()
{
    unsigned int n,k;
    cin>>n>>k;

    vector< vector<Butla> > butla;
    for(unsigned int i=0;i<n;i++)
    {
        butla.push_back(vector<Butla>());
    }

    for(unsigned int i=0;i<n;i++)
    {
        for(unsigned int j=0;j<=i;j++)
        {
            short rok;
            cin>>rok;
            butla[i].push_back(Butla(rok));
        }
    }

    UstalZasieg(butla);

    short rok_min = 2020;
    for(unsigned int i=0;i<n;i++)
    {
        for(unsigned int j=0;j<=i;j++)
        {
            if(butla[i][j].zasieg<=k && butla[i][j].rok<rok_min)
            {
                rok_min = butla[i][j].rok;
            }
        }
    }
    cout<<rok_min;
    return 0;
}