#include <bits/stdc++.h> using namespace std; int seq[500010]; int premin[500010]; int postmax[500010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; cin>>seq[0]; premin[0]=seq[0]; int minp=0; bool inc=1; for(int i=1;i<n;i++) { cin>>seq[i]; premin[i]=min(premin[i-1],seq[i]); minp=seq[i]<=seq[minp]?i:minp; if(seq[i]<=seq[i-1]) { inc=0; } } if(inc) { cout<<"NIE"; } else { postmax[n-1]=seq[n-1]; for(int i=n-2; i>=0; i--) { postmax[i]=max(postmax[i+1],seq[i]); } bool found=0; int c; for(c=0; c<n-1; c++) { if(premin[c]>=postmax[c+1]) { found=1; break; } } if(found) { cout<<"TAK\n"; for(int i=0; i<min(k-2,c); i++) { cout<<i+1<<" "; } cout<<c+1<<" "; for(int i=c+1; i<k-1; i++) { cout<<i+1<<" "; } } else if(k==2) cout<<"NIE"; else { if(minp==0) { int ma=0; for(int i=1; i<n;i++) { ma=seq[ma]<seq[i]?i:ma; } if(ma==n-1) { if(k==3) cout<<"NIE"; else { cout<<"TAK\n"; int c=0; while(seq[c]<seq[c+1]) c++; for(int i=0; i<min(k-4,c-1);i++) cout<<i+1<<" "; cout<<c<<" "<<c+1<<" "<<c+2<<" "; for(int i=c+2; i<k-1;i++) cout<<i+1<<" "; } } else { cout<<"TAK\n"; for(int i=0; i<min(k-3,ma-1);i++) cout<<i+1<<" "; cout<<ma<<" "<<ma+1<<" "; for(int i=ma+1; i<k-1;i++) cout<<i+1<<" "; } } else { cout<<"TAK\n"; for(int i=0; i<min(k-3,minp-1);i++) cout<<i+1<<" "; cout<<minp<<" "<<minp+1<<" "; for(int i=minp+1; i<k-1;i++) cout<<i+1<<" "; } } } }
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 103 104 105 106 107 108 109 110 111 112 | #include <bits/stdc++.h> using namespace std; int seq[500010]; int premin[500010]; int postmax[500010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; cin>>seq[0]; premin[0]=seq[0]; int minp=0; bool inc=1; for(int i=1;i<n;i++) { cin>>seq[i]; premin[i]=min(premin[i-1],seq[i]); minp=seq[i]<=seq[minp]?i:minp; if(seq[i]<=seq[i-1]) { inc=0; } } if(inc) { cout<<"NIE"; } else { postmax[n-1]=seq[n-1]; for(int i=n-2; i>=0; i--) { postmax[i]=max(postmax[i+1],seq[i]); } bool found=0; int c; for(c=0; c<n-1; c++) { if(premin[c]>=postmax[c+1]) { found=1; break; } } if(found) { cout<<"TAK\n"; for(int i=0; i<min(k-2,c); i++) { cout<<i+1<<" "; } cout<<c+1<<" "; for(int i=c+1; i<k-1; i++) { cout<<i+1<<" "; } } else if(k==2) cout<<"NIE"; else { if(minp==0) { int ma=0; for(int i=1; i<n;i++) { ma=seq[ma]<seq[i]?i:ma; } if(ma==n-1) { if(k==3) cout<<"NIE"; else { cout<<"TAK\n"; int c=0; while(seq[c]<seq[c+1]) c++; for(int i=0; i<min(k-4,c-1);i++) cout<<i+1<<" "; cout<<c<<" "<<c+1<<" "<<c+2<<" "; for(int i=c+2; i<k-1;i++) cout<<i+1<<" "; } } else { cout<<"TAK\n"; for(int i=0; i<min(k-3,ma-1);i++) cout<<i+1<<" "; cout<<ma<<" "<<ma+1<<" "; for(int i=ma+1; i<k-1;i++) cout<<i+1<<" "; } } else { cout<<"TAK\n"; for(int i=0; i<min(k-3,minp-1);i++) cout<<i+1<<" "; cout<<minp<<" "<<minp+1<<" "; for(int i=minp+1; i<k-1;i++) cout<<i+1<<" "; } } } } |