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

using namespace std;

int main()
{
	int levels, needed, year, index, min;

	cin >> levels >> needed;
	vector<vector<int> > bottles(levels);

	for (int i = 0; i < levels; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			cin >> year;
			bottles[i].push_back(year);
		}
	}

	min = bottles[0][0];

	for (int i = 0; i < levels && i < needed; i++)
	{
		if (bottles[i][0] < min)
		{
			min = bottles[i][0];
		}
	}

	for (int i = 0; i < levels && i < needed; i++)
	{
		index = bottles[i].size() - 1;
		if (bottles[i][index] < min)
		{
			min = bottles[i][index];
		}
	}


	for (int y = 0; y < levels; y++)
	{
		if (needed <= 0)
		{
			break;
		}

		for (unsigned int i = 0; i < bottles[y].size(); i++)
		{
			if (bottles[y][i] < min)
			{
				min = bottles[y][i];
			}

			needed--;
		}
	}

	cout << min << endl;

	return 0;
}