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
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n, k;
	vector<vector<int>> stack;
	cin >> n >> k;
	{
		int i = 0;
		for (; i < k && i < n; ++i)
		{
			stack.push_back(vector<int>());
			for (int j = 0; j < i + 1; ++j)
			{
				int a;
				cin >> a;
				stack.at(i).push_back(a);
			}
		}
		int temp;
		for (; i < n; ++i) cin >> temp;
	}

	int i{0}, j{0};
	int oldest{2019};
	while (i < k && i < n)
	{
		if (stack.at(i).at(j) < oldest)
			oldest = stack.at(i).at(j);
		if (stack.at(i).at(i - j) < oldest)
			oldest = stack.at(i).at(i - j);

		bool next = false;
		++j;
		next = j + 1 > int(float(i + 1) / 2 + 0.5);
		int field{1};
		if (!next)
			for (int l = 0; l < i; ++l)
			{
				field += ((l < j) ? l : j) + 1;
				if (field > k)
				{
					next = true;
					break;
				}
			}
		if (next)
		{
			++i;
			j = 0;
		}
	}
	cout << oldest << endl;
}