#include <bits/stdc++.h> #define ll long long #define pb push_back #define DUZ 2000000 #define MEGA 1000000005 using namespace std; ll a[DUZ]; ll suf[DUZ]; ll pre[DUZ]; bool res[DUZ]; void solve(){ vector <pair < int,int > > where; int N,K; cin>>N>>K; for(int i=1; i<=N; i++){ cin>>a[i]; where.pb({a[i],-i}); } sort(where.begin(),where.end()); int j=0; while(where[j].second==-(j+1)) j++; if(j==N+1){ //pracownik sie polepszal przez rok caly cout<<"NIE\n"; return; } int dolek=-where[j].second; //cout<<j<<"\n"; if(j==0){ if(K==2){ //czy sie da? //to zalezy pre[j+1]=a[j+1]; for(int i=j+2; i<=N; i++) pre[i]=min(pre[i-1],a[i]); suf[N]=a[N]; for(int i=N-1; i>=j+1; i--) suf[i]=max(suf[i+1],a[i]); int index=-1; for(int i=j+2; i<=N; i++) if(suf[i]<=pre[i-1]) index=i; if(index==-1){ cout<<"NIE\n"; return; } cout<<"TAK\n"; cout<<index-1<<" "; } if(K>=3){ cout<<"TAK\n"; int R; if(dolek==N){ if(K==N){ for(int i=1; i<=N-1; i++) cout<<i<<" "; return; }else{ R=K-2; for(int i=1; i<=R; i++) cout<<i<<" "; cout<<dolek-1<<" "; return; } return; }else{ if(K==N){ for(int i=1; i<=N-1; i++) cout<<i<<" "; return; } for(int i=1; i<=K-3; i++) cout<<i<<" "; R=K-3; if(R<dolek-1){ cout<<dolek-1<<" "; cout<<dolek<<" "; //cout<<dolek+1<<" "<<N<<"\n"; return; } if(R>=dolek-1){R++; cout<<R<<" ";} if(R>=dolek){R++; cout<<R<<" ";} //cout<<R+1<<N<<"\n"; return; } } }else{ if(K==2){ cout<<"NIE\n"; return; } if(K==3){ //czy sie da? //to zalezy pre[j+1]=a[j+1]; for(int i=j+2; i<=N; i++) pre[i]=min(pre[i-1],a[i]); suf[N]=a[N]; for(int i=N-1; i>=j+1; i--) suf[i]=max(suf[i+1],a[i]); int index=-1; for(int i=j+2; i<=N; i++) if(suf[i]<=pre[i-1]) index=i; if(index==-1){ cout<<"NIE\n"; return; } cout<<"TAK\n"; cout<<j<<" "; cout<<index-1<<" "; //cout<<index<<" "<<N<<"\n"; return; } if(K>=4){ cout<<"TAK\n"; res[j]=1; res[dolek-1]=1; res[dolek]=1; res[N]=1; int M=0; int R; for(int i=1; i<=N; i++) if(res[i]) M++; R=K-M; for(int i=1; i<=N; i++) if(R>0 && !res[i]){res[i]=1; R--;} int P=1; for(int i=1; i<=N-1; i++) if(res[i]){ cout<<i<<" "; P=i+1; } return; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(); solve(); 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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | #include <bits/stdc++.h> #define ll long long #define pb push_back #define DUZ 2000000 #define MEGA 1000000005 using namespace std; ll a[DUZ]; ll suf[DUZ]; ll pre[DUZ]; bool res[DUZ]; void solve(){ vector <pair < int,int > > where; int N,K; cin>>N>>K; for(int i=1; i<=N; i++){ cin>>a[i]; where.pb({a[i],-i}); } sort(where.begin(),where.end()); int j=0; while(where[j].second==-(j+1)) j++; if(j==N+1){ //pracownik sie polepszal przez rok caly cout<<"NIE\n"; return; } int dolek=-where[j].second; //cout<<j<<"\n"; if(j==0){ if(K==2){ //czy sie da? //to zalezy pre[j+1]=a[j+1]; for(int i=j+2; i<=N; i++) pre[i]=min(pre[i-1],a[i]); suf[N]=a[N]; for(int i=N-1; i>=j+1; i--) suf[i]=max(suf[i+1],a[i]); int index=-1; for(int i=j+2; i<=N; i++) if(suf[i]<=pre[i-1]) index=i; if(index==-1){ cout<<"NIE\n"; return; } cout<<"TAK\n"; cout<<index-1<<" "; } if(K>=3){ cout<<"TAK\n"; int R; if(dolek==N){ if(K==N){ for(int i=1; i<=N-1; i++) cout<<i<<" "; return; }else{ R=K-2; for(int i=1; i<=R; i++) cout<<i<<" "; cout<<dolek-1<<" "; return; } return; }else{ if(K==N){ for(int i=1; i<=N-1; i++) cout<<i<<" "; return; } for(int i=1; i<=K-3; i++) cout<<i<<" "; R=K-3; if(R<dolek-1){ cout<<dolek-1<<" "; cout<<dolek<<" "; //cout<<dolek+1<<" "<<N<<"\n"; return; } if(R>=dolek-1){R++; cout<<R<<" ";} if(R>=dolek){R++; cout<<R<<" ";} //cout<<R+1<<N<<"\n"; return; } } }else{ if(K==2){ cout<<"NIE\n"; return; } if(K==3){ //czy sie da? //to zalezy pre[j+1]=a[j+1]; for(int i=j+2; i<=N; i++) pre[i]=min(pre[i-1],a[i]); suf[N]=a[N]; for(int i=N-1; i>=j+1; i--) suf[i]=max(suf[i+1],a[i]); int index=-1; for(int i=j+2; i<=N; i++) if(suf[i]<=pre[i-1]) index=i; if(index==-1){ cout<<"NIE\n"; return; } cout<<"TAK\n"; cout<<j<<" "; cout<<index-1<<" "; //cout<<index<<" "<<N<<"\n"; return; } if(K>=4){ cout<<"TAK\n"; res[j]=1; res[dolek-1]=1; res[dolek]=1; res[N]=1; int M=0; int R; for(int i=1; i<=N; i++) if(res[i]) M++; R=K-M; for(int i=1; i<=N; i++) if(R>0 && !res[i]){res[i]=1; R--;} int P=1; for(int i=1; i<=N-1; i++) if(res[i]){ cout<<i<<" "; P=i+1; } return; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(); solve(); return 0; } |