1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>
using namespace std;

const int N = (int)2e3+10;
int a,minimum[N][N],n,k,wyn=2*N;

void solve(){
	cin>>n>>k;
	for (int i=1; i<=n; ++i){
		for (int j=1; j<=i; ++j){
			cin>>a;
			minimum[i][j]=(i-j+1)+minimum[i-1][j-1];
			if (minimum[i][j]<=k){
				wyn=min(wyn,a);
			}
		}
	}
	cout<<wyn<<'\n';
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	solve();
}