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

using namespace std;
using i64 = long long;
using i32 = int;

template<typename T> T load() { T x; cin >> x; return x; }
template<typename T> vector<T> loadN(int s) { vector<T> vt(s); for(auto& el : vt) el = load<T>(); return vt; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vt) { for(auto& el : vt) os << el << ' '; return os; }

i32 piramid_bottles(i32 n) { return  n * (n + 1) / 2; }

i32 bottle_cost(i32 pos, i32 level, i32 n) {
	auto all = piramid_bottles(n);
	auto on_left = pos;
	auto on_right = level - pos;
	auto levels_left = n - level - 1;
	if(on_left + on_right == 0) return 1;
	if(on_right < on_left) swap(on_right, on_left);
	if(on_left == 0) return all - levels_left - piramid_bottles(levels_left + on_right);
	
	auto parts = piramid_bottles(on_right + levels_left) + piramid_bottles(on_left + levels_left);
	auto common = piramid_bottles(max(0, levels_left - 1));
	return all - (parts - common);
}

i32 main() {
	ios::sync_with_stdio(false);
	
	auto n = load<i32>();
	auto desire = load<i32>();

	auto best = INT_MAX;

	for(i32 i = 0 ; i < n ; ++i)
		for(i32 j = 0 ; j <= i ; ++j) {
			auto age = load<i32>();
			if(bottle_cost(j, i, n) <= desire)
				best = min(best, age);

		}
			
	
	cout << best << '\n';
}