#include <bits/stdc++.h> using namespace std; vector <vector <pair<int,int>>> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin>>n>>k; v.resize(n+1); for(int i=1; i<=n; i++) { int x, odl=i-2; v[i].resize(i+1); for(int j=1; j<=i; j++) { cin>>x; if(j==1) v[i][j]={x, i}; else if(j==i) v[i][j]={x, i}; else if(j==i/2+1 && i%2!=0) { int tfu=v[i][j-1].second+1; v[i][j]={x,tfu}; } else { int tfu=v[i][j-1].second+odl; if(j>i/2 && i%2==0) v[i][j]={x, v[i][j-i/2+1].second}; else if(j>i/2 && i%2==1) v[i][j]={x, v[i][j-i/2].second}; else v[i][j]={x,tfu}; odl-=2; } } } int ans=30000; for(int i=1; i<=n; i++) { for(int j=1; j<=i; j++) { if(v[i][j].first<ans && v[i][j].second<=k) ans=v[i][j].first; //cout<<v[i][j].first<<":"<<v[i][j].second<<" "; } //cout<<endl; } cout<<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 45 46 47 48 49 50 51 52 53 | #include <bits/stdc++.h> using namespace std; vector <vector <pair<int,int>>> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin>>n>>k; v.resize(n+1); for(int i=1; i<=n; i++) { int x, odl=i-2; v[i].resize(i+1); for(int j=1; j<=i; j++) { cin>>x; if(j==1) v[i][j]={x, i}; else if(j==i) v[i][j]={x, i}; else if(j==i/2+1 && i%2!=0) { int tfu=v[i][j-1].second+1; v[i][j]={x,tfu}; } else { int tfu=v[i][j-1].second+odl; if(j>i/2 && i%2==0) v[i][j]={x, v[i][j-i/2+1].second}; else if(j>i/2 && i%2==1) v[i][j]={x, v[i][j-i/2].second}; else v[i][j]={x,tfu}; odl-=2; } } } int ans=30000; for(int i=1; i<=n; i++) { for(int j=1; j<=i; j++) { if(v[i][j].first<ans && v[i][j].second<=k) ans=v[i][j].first; //cout<<v[i][j].first<<":"<<v[i][j].second<<" "; } //cout<<endl; } cout<<ans; return 0; } |