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
#include <iostream>
#include <set>
using namespace std;

class Wino {
public:
	int y = 0;
	int ileNadZ = 0;

	bool operator< (const Wino& msgObj) const {
		return (this->y < msgObj.y);
	}

	friend ostream& operator<<(ostream& os, const Wino& obj);

};

ostream& operator<<(ostream& os, const Wino& obj)
{
	os << "Wino" << obj.y << ";" << obj.ileNadZ;

	return os;
}

int p(int lvl) {
	return (lvl + 1) * lvl / 2;
}

int main(int argc, char** argv) {
	int n, k;

	cin >> n >> k;

	Wino* najstarsze = NULL;

	for (int i = 0; i < n; i++) {
		bool czyJakisZK = false;
		for (int j = 0; j <= i; j++) {
			int year;
			cin >> year;
			Wino* w = new Wino();
			w->y = year;
			w->ileNadZ = p(i + 1) - p(j) - p(i - j);
			if (w->ileNadZ <= k) {
				if (najstarsze == 0 || (najstarsze->y >= w->y)) {
					najstarsze = w;
				}
				czyJakisZK = true;
			}
		}
		if (!czyJakisZK)
			break;
	}

	if (najstarsze != NULL)
		cout << najstarsze->y << endl;

	return 0;
}