#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0);
int n,k;
cin>>n>>k;
vector<int>a(n);
int posHI,posLO,pos2,pos4;
int hi=-1,lo=INT_MAX;
bool ok=true;
for(int i=0;i<n;i++){
cin>>a[i];
if(hi<a[i]){
hi=a[i];
posHI=i;
}else if(ok==true){
ok=false;
pos4=i;
}
if(lo>=a[i]){
lo=a[i];
posLO=i;
}
}
bool ans=true;
if(k==2){
ans=false;
vector<int>left(n),right(n);
left[0]=a[0];
left[1]=a[0];
for(int i=1;i<n;i++)
left[i]=min(left[i-1],a[i-1]);
right[n-1]=a[n-1];
right[n-2]=a[n-1];
for(int i=n-3;i>=0;i--)
right[i]=max(right[i+1],a[i+1]);
/*
for(int i=0;i<n;i++)
cout<<left[i]<<' '<<right[i]<<" ";
*/
for(int i=0;i<n;i++)
if(left[i]>=right[i]){
pos2=i+1;
ans=true;
break;
}
}
if(k==3 and posLO==0 and posHI==n-1)
ans=false;
else if(k>=4 and ok==true)
ans=false;
if(ans==false)
return cout<<"NIE"<<'\n',0;
cout<<"TAK"<<'\n';
if(k==2)
cout<<pos2;
else if(k==3){
if(posLO!=0)
cout<<posLO<<' '<<posLO+1;
else
cout<<posHI<<' '<<posHI+1;
}
else{
set<int>ends;
ends.insert(pos4);
if(pos4+1!=n)
ends.insert(pos4+1);
else
ends.insert(pos4-1);
for(int i=1;i<n;i++){
if(ends.size()==k-1)
break;
ends.insert(i);
}
for(int x:ends)
cout<<x<<' ';
}
cout<<'\n';
}
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 | #include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0); int n,k; cin>>n>>k; vector<int>a(n); int posHI,posLO,pos2,pos4; int hi=-1,lo=INT_MAX; bool ok=true; for(int i=0;i<n;i++){ cin>>a[i]; if(hi<a[i]){ hi=a[i]; posHI=i; }else if(ok==true){ ok=false; pos4=i; } if(lo>=a[i]){ lo=a[i]; posLO=i; } } bool ans=true; if(k==2){ ans=false; vector<int>left(n),right(n); left[0]=a[0]; left[1]=a[0]; for(int i=1;i<n;i++) left[i]=min(left[i-1],a[i-1]); right[n-1]=a[n-1]; right[n-2]=a[n-1]; for(int i=n-3;i>=0;i--) right[i]=max(right[i+1],a[i+1]); /* for(int i=0;i<n;i++) cout<<left[i]<<' '<<right[i]<<" "; */ for(int i=0;i<n;i++) if(left[i]>=right[i]){ pos2=i+1; ans=true; break; } } if(k==3 and posLO==0 and posHI==n-1) ans=false; else if(k>=4 and ok==true) ans=false; if(ans==false) return cout<<"NIE"<<'\n',0; cout<<"TAK"<<'\n'; if(k==2) cout<<pos2; else if(k==3){ if(posLO!=0) cout<<posLO<<' '<<posLO+1; else cout<<posHI<<' '<<posHI+1; } else{ set<int>ends; ends.insert(pos4); if(pos4+1!=n) ends.insert(pos4+1); else ends.insert(pos4-1); for(int i=1;i<n;i++){ if(ends.size()==k-1) break; ends.insert(i); } for(int x:ends) cout<<x<<' '; } cout<<'\n'; } |
English