#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int n, k;
const int inf=1e9+3;
int mod(int a){
if(a<0) return -a;
else return a;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin>>n>>k;
int res=inf;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
int x, cost;
cin>>x;
cost=min(mod(i-j+1), mod(j));
if(cost>0) cost*=(i-cost+1);
else cost=i;
if(cost<=k) res=min(res, x);
}
}
cout<<res<<"\n";
}
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 | #include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; int n, k; const int inf=1e9+3; int mod(int a){ if(a<0) return -a; else return a; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin>>n>>k; int res=inf; for(int i=1; i<=n; i++){ for(int j=1; j<=i; j++){ int x, cost; cin>>x; cost=min(mod(i-j+1), mod(j)); if(cost>0) cost*=(i-cost+1); else cost=i; if(cost<=k) res=min(res, x); } } cout<<res<<"\n"; } |
English