#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
int n, k; cin>>n>>k;
vector<int> tab;
for(int i = 0; i < n; i++){
int a; cin>>a;
tab.push_back(a);
}
bool dasie = false;
vector<bool> odp(n);
if(k==2){
vector<int> suf(n);
suf[n-1] = tab[n-1];
for(int i = n-2; i; i--){
suf[i] = max(tab[i], suf[i+1]);
}
int mini = tab[0];
for(int i = 1; i < n; i++){
if(mini>=suf[i]){
dasie = true;
odp[i-1] = true;
break;
}
mini = min(mini, tab[i]);
}
}else if(k==3){
int maks = 0;
int id = -1;
for(int i = n-1; i>=0; i--){
if(tab[i]>=maks){
maks = tab[i];
id = i;
}
}
if(id == n-1){
for(int i = 1; i < n; i++){
if(tab[i]<=tab[0]){
dasie = true;
odp[i] = 1;
odp[i-1] = 1;
}
}
}else{
dasie = true;
odp[id] = 1;
if(id>0) odp[id-1] = 1;
else odp[1] = 1;
}
}else if(k>=4){
dasie = false;
for(int i = 0; i < n-1; i++){
if(tab[i]>=tab[i+1]){
odp[i] = true;
odp[i+1] = true;
if(i>0) odp[i-1] = true;
k-=3;
dasie = true;
break;
}
}
for(int i = 0; i < n; i++){
if(k<=1) break;
if(!odp[i]){
odp[i] = true;
k--;
}
}
}
if(!dasie) cout<<"NIE\n";
else{
cout<<"TAK\n";
for(int i = 0; i < n; i++) if(odp[i]) cout<<i+1<<' ';
cout<<'\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 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); int n, k; cin>>n>>k; vector<int> tab; for(int i = 0; i < n; i++){ int a; cin>>a; tab.push_back(a); } bool dasie = false; vector<bool> odp(n); if(k==2){ vector<int> suf(n); suf[n-1] = tab[n-1]; for(int i = n-2; i; i--){ suf[i] = max(tab[i], suf[i+1]); } int mini = tab[0]; for(int i = 1; i < n; i++){ if(mini>=suf[i]){ dasie = true; odp[i-1] = true; break; } mini = min(mini, tab[i]); } }else if(k==3){ int maks = 0; int id = -1; for(int i = n-1; i>=0; i--){ if(tab[i]>=maks){ maks = tab[i]; id = i; } } if(id == n-1){ for(int i = 1; i < n; i++){ if(tab[i]<=tab[0]){ dasie = true; odp[i] = 1; odp[i-1] = 1; } } }else{ dasie = true; odp[id] = 1; if(id>0) odp[id-1] = 1; else odp[1] = 1; } }else if(k>=4){ dasie = false; for(int i = 0; i < n-1; i++){ if(tab[i]>=tab[i+1]){ odp[i] = true; odp[i+1] = true; if(i>0) odp[i-1] = true; k-=3; dasie = true; break; } } for(int i = 0; i < n; i++){ if(k<=1) break; if(!odp[i]){ odp[i] = true; k--; } } } if(!dasie) cout<<"NIE\n"; else{ cout<<"TAK\n"; for(int i = 0; i < n; i++) if(odp[i]) cout<<i+1<<' '; cout<<'\n'; } return 0; } |
English