#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int t[1000009];
int l[1000009], p[1000009];
int main(){
ios_base::sync_with_stdio(false);
int n, k;
cin>>n>>k;
for(int i=1; i<=n; i++){
cin>>t[i];
}
vector<int> res;
bool ok = false;
//k==2
l[0]=1e9+1;
for(int i=1; i<=n; i++){
l[i] = min(l[i-1], t[i]);
}
for(int i=n; i>0; i--){
p[i] = max(p[i+1], t[i]);
}
for(int i=1; i<n; i++){
if(l[i] >= p[i+1]){
res.push_back(i);
ok=true;
break;
}
}
//k==3
if(k>=3 && ok==false){
int mini = t[1];
int pos = 1;
for(int i=2; i<=n; i++){
if(t[i] <= mini){
mini = t[i];
pos = i;
}
}
if(pos > 1){
ok = true;
res.push_back(pos-1);
if(pos < n){
res.push_back(pos);
}
}
if(ok==false){
int maxi = t[n];
pos = n;
for(int i=n-1; i>0; i--){
if(t[i] >= maxi){
maxi = t[i];
pos = i;
}
}
if(pos < n){
ok = true;
res.push_back(pos);
if(pos > 1){
res.push_back(pos-1);
}
}
}
}
//k>3
if(k>3 && ok==false){
set<int> s;
int mini = 1e9+1;
int pos = 0;
for(int i=1; i<=n; i++){
if(s.find(t[i]) == s.end()){
s.insert(t[i]);
}
else{
if(t[i] < mini){
mini = t[i];
pos = i;
}
}
}
if(pos != 0){
ok=true;
if(pos > 1){
res.push_back(pos-1);
}
if(pos < n){
res.push_back(pos);
}
}
for(int i=2; i<=n; i++){
if(t[i]==mini){
res.push_back(i-1);
break;
}
}
}
//
if(ok){
int it=1;
while(int(res.size()) < k-1){
bool e = true;
for(int j=0; j<min(int(res.size()), 3); j++){
if(it == res[j]){
e=false;
}
}
if(e){
res.push_back(it);
}
it++;
}
}
if(ok){
cout<<"TAK\n";
sort(res.begin(), res.end());
for(auto j : res){
cout<<j<<" ";
}
cout<<"\n";
}
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int t[1000009]; int l[1000009], p[1000009]; int main(){ ios_base::sync_with_stdio(false); int n, k; cin>>n>>k; for(int i=1; i<=n; i++){ cin>>t[i]; } vector<int> res; bool ok = false; //k==2 l[0]=1e9+1; for(int i=1; i<=n; i++){ l[i] = min(l[i-1], t[i]); } for(int i=n; i>0; i--){ p[i] = max(p[i+1], t[i]); } for(int i=1; i<n; i++){ if(l[i] >= p[i+1]){ res.push_back(i); ok=true; break; } } //k==3 if(k>=3 && ok==false){ int mini = t[1]; int pos = 1; for(int i=2; i<=n; i++){ if(t[i] <= mini){ mini = t[i]; pos = i; } } if(pos > 1){ ok = true; res.push_back(pos-1); if(pos < n){ res.push_back(pos); } } if(ok==false){ int maxi = t[n]; pos = n; for(int i=n-1; i>0; i--){ if(t[i] >= maxi){ maxi = t[i]; pos = i; } } if(pos < n){ ok = true; res.push_back(pos); if(pos > 1){ res.push_back(pos-1); } } } } //k>3 if(k>3 && ok==false){ set<int> s; int mini = 1e9+1; int pos = 0; for(int i=1; i<=n; i++){ if(s.find(t[i]) == s.end()){ s.insert(t[i]); } else{ if(t[i] < mini){ mini = t[i]; pos = i; } } } if(pos != 0){ ok=true; if(pos > 1){ res.push_back(pos-1); } if(pos < n){ res.push_back(pos); } } for(int i=2; i<=n; i++){ if(t[i]==mini){ res.push_back(i-1); break; } } } // if(ok){ int it=1; while(int(res.size()) < k-1){ bool e = true; for(int j=0; j<min(int(res.size()), 3); j++){ if(it == res[j]){ e=false; } } if(e){ res.push_back(it); } it++; } } if(ok){ cout<<"TAK\n"; sort(res.begin(), res.end()); for(auto j : res){ cout<<j<<" "; } cout<<"\n"; } else{ cout<<"NIE\n"; } return 0; } |
English