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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<iostream>
#include<vector>
#include<list>
#include<cassert>
#include <algorithm>
#include <memory>
#include <tuple>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <iostream>
#include <string>
#include <math.h>    

using namespace std;

unsigned long long N, K;

int main()
{
	cin >> N;
	cin >> K;

	vector<unsigned int> kVec(N, 0);
	vector<unsigned int> kVec2(N, 0);

	vector<unsigned int>* vec_ptr = &kVec;
	vector<unsigned int>* vec_curr_ptr = &kVec2;

	unsigned int minK = -1;

	for (unsigned long long i = 0; i < N && i < K; ++i)
	{
		for (unsigned long long j = 0; j <= i; ++j)
		{
			unsigned long long num;
			cin >> num;

			if (i == 0)
			{
				minK = num;


				continue;
			}

			unsigned long long j2 = j + 1;
			if (j2 > (i + 2) / 2)
			{
				j2 = (i - j + 1);
			}
				
			auto& vec = *vec_ptr;
			unsigned long long current_k  = j >= 1 ? max(vec[j], vec[j - 1]) + j2 +1 : vec[j] + j2 +1;

			if (current_k <= K && num < minK)
			{
				minK = num;
				if (minK == 1)
				{
					cout << minK;
					return 0;
				}

			}

			(*vec_curr_ptr)[j] = current_k-1;
		}

		auto* temp = vec_ptr;
		vec_ptr = vec_curr_ptr;
		vec_curr_ptr = temp;

	}

	cout << minK;

	return 0;
}