#include<bits/stdc++.h>
#define MAGICLINE ios_base::sync_with_stdio(0)
#define FOR(i, a, b) for(auto (i)=(a);(i)<=(b);(i)++)
#define DFOR(i, a, b) for(auto (i)=(a);(i)>=(b);(i)--)
#define REP(i, a) for(auto (i)=0;(i)<(a);(i)++)
#define ALL(V) (V).begin(), (V).end()
#define translate(V) sort(ALL(V)); (V).resize(unique(ALL(V))-(V).begin())
#define roll(a, b) ((a)+rand()%((b)-(a)+1))
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define even(a) (!((a) & 1))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, int> PLI;
typedef priority_queue<int> PQI;
typedef priority_queue<LL> PQL;
const int MN = 2003, INF = 1e9+7;
int inp[MN][MN], T[MN][MN];
int f(int x){
return x*(x+1)/2;
}
int main(){
MAGICLINE;
int n, k; scanf("%d %d", &n, &k);
int ans = INF;
FOR(i, 1, n){
FOR(j, 1, i){
scanf("%d", &inp[i][j]);
T[i][j] = min(T[i-1][j-1]+i-j, T[i-1][j]+j-1)+1;
if(k >= T[i][j]) ans = min(ans, inp[i][j]);
}
}
printf("%d\n", ans);
return 0;
}
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 | #include<bits/stdc++.h> #define MAGICLINE ios_base::sync_with_stdio(0) #define FOR(i, a, b) for(auto (i)=(a);(i)<=(b);(i)++) #define DFOR(i, a, b) for(auto (i)=(a);(i)>=(b);(i)--) #define REP(i, a) for(auto (i)=0;(i)<(a);(i)++) #define ALL(V) (V).begin(), (V).end() #define translate(V) sort(ALL(V)); (V).resize(unique(ALL(V))-(V).begin()) #define roll(a, b) ((a)+rand()%((b)-(a)+1)) #define pb push_back #define mp make_pair #define se second #define fs first #define even(a) (!((a) & 1)) using namespace std; typedef long long LL; typedef long double LD; typedef pair<int, int> PII; typedef pair<LL, int> PLI; typedef priority_queue<int> PQI; typedef priority_queue<LL> PQL; const int MN = 2003, INF = 1e9+7; int inp[MN][MN], T[MN][MN]; int f(int x){ return x*(x+1)/2; } int main(){ MAGICLINE; int n, k; scanf("%d %d", &n, &k); int ans = INF; FOR(i, 1, n){ FOR(j, 1, i){ scanf("%d", &inp[i][j]); T[i][j] = min(T[i-1][j-1]+i-j, T[i-1][j]+j-1)+1; if(k >= T[i][j]) ans = min(ans, inp[i][j]); } } printf("%d\n", ans); return 0; } |
English