#include<bits/stdc++.h> using namespace std; int tab[500009]; int Minn[500009]; int Maxx[500009]; bool zaj[500009]; int main() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,k; cin>>n>>k; for(int i=1;i<=n;i++) { cin>>tab[i]; } Minn[0]=INT_MAX; for(int i=1;i<=n;i++) { Minn[i]=min(Minn[i-1],tab[i]); } for(int i=n;i>=1;i--) { Maxx[i]=max(Maxx[i+1],tab[i]); } if(k==2) { for(int i=1;i<=n-1;i++) { if(Minn[i]>=Maxx[i+1]) { cout<<"TAK"<<endl<<i<<endl; return 0; } } } else if(k==3) { for(int i=1;i<=n-2;i++) { if(Minn[i]>=tab[i+1]||tab[i+1]>=Maxx[i+2]) { cout<<"TAK"<<endl<<i<<" "<<i+1<<endl; return 0; } } } else { bool cv=0; for(int i=1;i<=n-1;i++) { if(tab[i]>=tab[i+1]) { cv=1; zaj[i]=1; zaj[i-1]=1; zaj[i+1]=1; k--; if(i!=1){k--;} if(i!=n-1){k--;} break; } } if(cv==1) { cout<<"TAK"<<endl; for(int i=1;i<n;i++) { if(zaj[i]==0&&k>1) { k--; zaj[i]=1; } if(zaj[i]==1) { cout<<i<<" "; } } cout<<endl; return 0; } } cout<<"NIE"<<endl; 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 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 | #include<bits/stdc++.h> using namespace std; int tab[500009]; int Minn[500009]; int Maxx[500009]; bool zaj[500009]; int main() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,k; cin>>n>>k; for(int i=1;i<=n;i++) { cin>>tab[i]; } Minn[0]=INT_MAX; for(int i=1;i<=n;i++) { Minn[i]=min(Minn[i-1],tab[i]); } for(int i=n;i>=1;i--) { Maxx[i]=max(Maxx[i+1],tab[i]); } if(k==2) { for(int i=1;i<=n-1;i++) { if(Minn[i]>=Maxx[i+1]) { cout<<"TAK"<<endl<<i<<endl; return 0; } } } else if(k==3) { for(int i=1;i<=n-2;i++) { if(Minn[i]>=tab[i+1]||tab[i+1]>=Maxx[i+2]) { cout<<"TAK"<<endl<<i<<" "<<i+1<<endl; return 0; } } } else { bool cv=0; for(int i=1;i<=n-1;i++) { if(tab[i]>=tab[i+1]) { cv=1; zaj[i]=1; zaj[i-1]=1; zaj[i+1]=1; k--; if(i!=1){k--;} if(i!=n-1){k--;} break; } } if(cv==1) { cout<<"TAK"<<endl; for(int i=1;i<n;i++) { if(zaj[i]==0&&k>1) { k--; zaj[i]=1; } if(zaj[i]==1) { cout<<i<<" "; } } cout<<endl; return 0; } } cout<<"NIE"<<endl; return 0; } |