#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; vector<int> seq(n); for(auto &i : seq) cin>>i; vector<bool> used(n-1); int count = 1; if(k==2){ set<pair<int,int>> a, b; for(int i=1;i<n;++i) b.insert({seq[i],i}); a.insert({seq[0],0}); bool done = false; for(int i=1;i<n;++i){ if(a.begin()->first >= b.rbegin()->first){ done = true; // cout<<"TAK\n"; cout<<"TAK\n"<<i<<'\n'; break; } a.insert({seq[i],i}); b.erase({seq[i],i}); } if(!done) cout<<"NIE\n"; } if(k==3){ int mi=INT_MAX,mx=INT_MIN; for(int i=0;i<n;++i){ mi = min(mi, seq[i]); mx = max(mx, seq[i]); } bool done = false; for(int i=0;i<n-1;++i){ if(seq[i] == mx){ done = true; cout<<"TAK\n"; if(i==0){ cout<<1<<' '<<2<<'\n'; } else{ cout<<i<< ' '<<i+1<<'\n'; } break; } } if(!done){ for(int i=1;i<n;++i){ if(seq[i] == mi){ done=true; cout<<"TAK\n"; if(i == n-1){ cout<<n-2<<' '<<n-1<<'\n'; } else{ cout<<i<<' '<<i+1<<'\n'; } break; } } } if(!done) cout<<"NIE\n"; } if(k>=4){ for(int i=0;i<n-1;++i){ if(seq[i]>=seq[i+1]){ if(i>0){ count++; used[i-1]=true; } count++; used[i] = true; if(i<n-1){ count++; used[i+1]=true; } break; } } if(count > 1){ cout<<"TAK\n"; for(int i=0;i<n-1;++i){ if(count<k && !used[i]){ count++; used[i] = true; } if(used[i]) cout<<i+1<<' '; } } else cout<<"NIE\n"; } 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 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; vector<int> seq(n); for(auto &i : seq) cin>>i; vector<bool> used(n-1); int count = 1; if(k==2){ set<pair<int,int>> a, b; for(int i=1;i<n;++i) b.insert({seq[i],i}); a.insert({seq[0],0}); bool done = false; for(int i=1;i<n;++i){ if(a.begin()->first >= b.rbegin()->first){ done = true; // cout<<"TAK\n"; cout<<"TAK\n"<<i<<'\n'; break; } a.insert({seq[i],i}); b.erase({seq[i],i}); } if(!done) cout<<"NIE\n"; } if(k==3){ int mi=INT_MAX,mx=INT_MIN; for(int i=0;i<n;++i){ mi = min(mi, seq[i]); mx = max(mx, seq[i]); } bool done = false; for(int i=0;i<n-1;++i){ if(seq[i] == mx){ done = true; cout<<"TAK\n"; if(i==0){ cout<<1<<' '<<2<<'\n'; } else{ cout<<i<< ' '<<i+1<<'\n'; } break; } } if(!done){ for(int i=1;i<n;++i){ if(seq[i] == mi){ done=true; cout<<"TAK\n"; if(i == n-1){ cout<<n-2<<' '<<n-1<<'\n'; } else{ cout<<i<<' '<<i+1<<'\n'; } break; } } } if(!done) cout<<"NIE\n"; } if(k>=4){ for(int i=0;i<n-1;++i){ if(seq[i]>=seq[i+1]){ if(i>0){ count++; used[i-1]=true; } count++; used[i] = true; if(i<n-1){ count++; used[i+1]=true; } break; } } if(count > 1){ cout<<"TAK\n"; for(int i=0;i<n-1;++i){ if(count<k && !used[i]){ count++; used[i] = true; } if(used[i]) cout<<i+1<<' '; } } else cout<<"NIE\n"; } return 0; } |