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

long minimum(long x, long y) {
        if (x < y) {
                return x;
	} else {
        	return y;
	}
}

long minimum(long x, long y, long z) {
	return minimum(x, minimum(y, z));
}

int main() {
	long n;
	long k;
	long x;
	long maxYear = 2019;
	cin>>n;
	cin>>k;

	long* minPi = new long[n];
	long* L = new long[n];
	long* P = new long[n];

	for (long i = 0; i < n; ++i) {
		minPi[i] = maxYear + 1;
		for (long j = 0; j < i+1; ++j) {
			cin>>x;
			if (x < minPi[i]) minPi[i] = x;
			if (i == 0) {
				L[i] = x;
				P[i] = x;
			} else {
				if (j == 0) L[i] = minimum(x, L[i-1]);
				if (j == i) P[i] = minimum(x, P[i-1]);
			}
		}
		if (i > 0) minPi[i] = minimum(minPi[i], minPi[i-1]);
	}

	if (k <= n) {
		cout << minimum(minPi[k/2], L[k-1], P[k-1]);
	} else if (k < 2*n) {
		cout << minimum(minPi[k/2], L[n-1], P[n-1]);
	} else {
		cout << minimum(minPi[n-1], L[n-1], P[n-1]);
	}

	return 0;
}