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

using namespace std;

int main(){
	
	int n, k, lowest;
	cin >> n >> k;
	int arr1[n], arr2[n];
	
	cin >> lowest;
	arr2[0] = 0;
	
	int a, increment;
	for(int i = 1; i < n; ++i){
		increment = i;
		cin >> a;
		if(a < lowest && i < k){
			lowest = a;
		}
		
		for(int j = 1; j <= i; ++j){
			cin >> a;
			arr1[j] = arr2[j - 1] + increment--;
			if(a < lowest && arr1[j] < k){
				lowest = a;
			}
		}
		arr1[0] = i;
		for(int j = 0; j <= i; ++j) arr2[j] = arr1[j];
	}
	
	cout << lowest << endl;
	
	return 0;
}