/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> #define ll long long using namespace std; const ll q=1048577; ll n,k,t[q],pre[q],suf[q]; int main() { cin>>n>>k; ll spr=0,x,x_max=0,x_min=n+1,mini=1e9+1,maxi=0; for(ll i=1; i<=n; i++){ cin>>t[i]; mini=min(mini,t[i]); if(t[i]==mini) x_min=i; maxi=max(maxi,t[i]); if(t[i]==maxi && t[x_max]<t[i]) x_max=i; if(t[i]<=t[i-1]){ spr=1; x=i; } } if(spr==0){ cout<<"NIE"; return 0; } set <ll> s; if(k>=4){ if(x!=n) s.insert(x); s.insert(x-1); s.insert(x-2); ll licz=1; while(s.size()!=k-1){ s.insert(licz); licz++; } } else if(k==3){ //cout<<x_min<<" "<<x_max<<"\n"; if(x_min==1 && x_max==n){ cout<<"NIE"; return 0; } if(x_min!=1){ s.insert(x_min-1); s.insert(x_min); } else if(x_max!=n){ s.insert(x_max); s.insert(x_max-1); } ll licz=1; while(s.size()!=k-1){ s.insert(licz); licz++; } } else{ suf[n+1]=0;; pre[0]=1e9+1; for(ll i=1; i<=n; i++){ pre[i]=min(pre[i-1],t[i]); //cout<<pre[i]<<" "; } for(ll i=n; i>=1; i--){ suf[i]=max(suf[i+1],t[i]); //cout<<suf[i]<<" "; } spr=0; for(ll i=1; i<n; i++){ if(pre[i]>suf[i+1]){ s.insert(i); spr=1; } if(spr==1) break; } if(spr==0){ cout<<"NIE"; return 0; } } cout<<"TAK\n"; for(auto it=s.begin(); it!=s.end(); it++){ cout<<*it<<" "; } 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | /****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> #define ll long long using namespace std; const ll q=1048577; ll n,k,t[q],pre[q],suf[q]; int main() { cin>>n>>k; ll spr=0,x,x_max=0,x_min=n+1,mini=1e9+1,maxi=0; for(ll i=1; i<=n; i++){ cin>>t[i]; mini=min(mini,t[i]); if(t[i]==mini) x_min=i; maxi=max(maxi,t[i]); if(t[i]==maxi && t[x_max]<t[i]) x_max=i; if(t[i]<=t[i-1]){ spr=1; x=i; } } if(spr==0){ cout<<"NIE"; return 0; } set <ll> s; if(k>=4){ if(x!=n) s.insert(x); s.insert(x-1); s.insert(x-2); ll licz=1; while(s.size()!=k-1){ s.insert(licz); licz++; } } else if(k==3){ //cout<<x_min<<" "<<x_max<<"\n"; if(x_min==1 && x_max==n){ cout<<"NIE"; return 0; } if(x_min!=1){ s.insert(x_min-1); s.insert(x_min); } else if(x_max!=n){ s.insert(x_max); s.insert(x_max-1); } ll licz=1; while(s.size()!=k-1){ s.insert(licz); licz++; } } else{ suf[n+1]=0;; pre[0]=1e9+1; for(ll i=1; i<=n; i++){ pre[i]=min(pre[i-1],t[i]); //cout<<pre[i]<<" "; } for(ll i=n; i>=1; i--){ suf[i]=max(suf[i+1],t[i]); //cout<<suf[i]<<" "; } spr=0; for(ll i=1; i<n; i++){ if(pre[i]>suf[i+1]){ s.insert(i); spr=1; } if(spr==1) break; } if(spr==0){ cout<<"NIE"; return 0; } } cout<<"TAK\n"; for(auto it=s.begin(); it!=s.end(); it++){ cout<<*it<<" "; } return 0; } |