#include <bits/stdc++.h> using namespace std; int n,k,x; int max_k=2; int minimals[2002000]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); for(int i = 0; i<2002000; i++) minimals[i]=INT_MAX; cin>>n>>k; cin>>x; minimals[1]=min(minimals[1],x); cin>>x; minimals[2]=min(minimals[2],x); cin>>x; minimals[2]=min(minimals[2],x); for(int i = 3; i<=n; i++){ if(i%2==1) { int add_p=((i/2) - 1)*2 + 1; int add_res=add_p; cin>>x; max_k=max(max_k,i); minimals[i]=min(minimals[i],x); for(int j = 2; j<=i/2; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_p-=2; add_res+=add_p; } cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_res--; add_p=3; for(int j = i/2 + 2; j<=i; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_res-=add_p; add_p+=2; } } else //even { int add_p=((i/2) - 1)*2; int add_res=add_p; cin>>x; max_k=max(max_k,i); minimals[i]=min(minimals[i],x); for(int j = 2; j<=i/2; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_p-=2; add_res+=add_p; } //add_res--; add_p=2; for(int j = i/2 + 1; j<=i; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_res-=add_p; add_p+=2; } } } /* for(int i = 1 ; i<=max_k; i++){ cout<<minimals[i]<<endl; }*/ for(int i = 1 ; i<=n*(n+1)*0.5; i++){ minimals[i]=min(minimals[i],minimals[i-1]); //cout<<i<<" "<<minimals[i]<<endl; } cout<<minimals[k]; }
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #include <bits/stdc++.h> using namespace std; int n,k,x; int max_k=2; int minimals[2002000]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); for(int i = 0; i<2002000; i++) minimals[i]=INT_MAX; cin>>n>>k; cin>>x; minimals[1]=min(minimals[1],x); cin>>x; minimals[2]=min(minimals[2],x); cin>>x; minimals[2]=min(minimals[2],x); for(int i = 3; i<=n; i++){ if(i%2==1) { int add_p=((i/2) - 1)*2 + 1; int add_res=add_p; cin>>x; max_k=max(max_k,i); minimals[i]=min(minimals[i],x); for(int j = 2; j<=i/2; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_p-=2; add_res+=add_p; } cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_res--; add_p=3; for(int j = i/2 + 2; j<=i; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_res-=add_p; add_p+=2; } } else //even { int add_p=((i/2) - 1)*2; int add_res=add_p; cin>>x; max_k=max(max_k,i); minimals[i]=min(minimals[i],x); for(int j = 2; j<=i/2; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_p-=2; add_res+=add_p; } //add_res--; add_p=2; for(int j = i/2 + 1; j<=i; j++){ cin>>x; max_k=max(max_k,i+add_res); minimals[i+add_res]=min(minimals[i+add_res],x); add_res-=add_p; add_p+=2; } } } /* for(int i = 1 ; i<=max_k; i++){ cout<<minimals[i]<<endl; }*/ for(int i = 1 ; i<=n*(n+1)*0.5; i++){ minimals[i]=min(minimals[i],minimals[i-1]); //cout<<i<<" "<<minimals[i]<<endl; } cout<<minimals[k]; } |