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
#include <iostream>
#include <vector>

using namespace std;


unsigned long long slab(unsigned long long i) {
	if (i < 0)
		return 0;
	unsigned long long tmp = 0;
	for (; i > 0; i--) {
		tmp += i;
	}
	return tmp;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	unsigned long long height, needed, tmp,r_min,dost;
	vector<pair<unsigned long long, unsigned long long>> beczki;
	cin >> height >> needed;
	for (unsigned long long gleb = 1; gleb <= height; gleb++) {
		for (unsigned long long nr = 1; nr < gleb + 1; nr++) {
			cin >> tmp;
			if (nr == 1 or nr == gleb) {
				dost = gleb;

			}
			else {
				dost = beczki[slab(gleb - 2) + nr - 2].second + beczki[slab(gleb - 2) + nr - 1].second - beczki[slab(gleb - 3) + nr - 2].second + 1;
			}

			beczki.push_back(make_pair(tmp,dost));

		}
	}
	r_min = beczki[0].first;
	unsigned long long dupa;
	for (auto x : beczki) {
		//cout <<'\n'<< x.dost << " ";
		if (x.second <= needed and x.first < r_min) {
			r_min = x.first;
			
		}
			
	}
	cout << r_min;
}