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
// Marcin Knapik, Potyczki Algorytmiczne 2019, runda pierwsza, zadanie wina [B]
// zlozonosc: O(n*n)

#include<bits/stdc++.h>
using namespace std;

#define ll long long

ll n, m;
const int N = 2007;

ll na[N][N];
ll tab[N][N];

void solve(){
	cin >> n >> m;
	ll ans = 100000;

	na[1][1] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j<=i; j++){
			cin >> tab[i][j];
			if(i+j>2){
				na[i][j] = na[i-1][j-1] + na[i-1][j] - na[i-2][j-1];
			}
			na[i][j]++;
			if(na[i][j] <= m)
				ans = min(ans, tab[i][j]);
		}
	}
	cout << ans << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	solve();
}