#include <bits/stdc++.h>
#include <queue>
using namespace std;
int n,k;
int t[500000];
int minn[500000];
int maxx[500000];
void read() {
cin>>n>>k;
for(int i =0;i<n;i++){
cin>>t[i];
}
}
void solve() {
read();
if(k>=4){
// szukamy miejsca gdzie t[i-1]>=t[i]
bool ok = true;
for(int i = 1;i<n;i++){
if(t[i-1]>=t[i]){
cout<<"TAK\n";
//(i-1|i|i+1)
int s =0;
if(i-1==0)s++;
if(i+1==n)s++;
k-=3;
k+=s;
int j = 1;
while(j<i-1 && k> 0){
cout<<j<<" ";
j++;
k--;
}
if(i-1!=0)
cout<<i-1<<" ";
cout<<i<<" ";
j = i+1;
while(j<n && k> 0){
cout<<j<<" ";
j++;
k--;
}
ok = false;
break;
}
}
if(ok){
cout<<"NIE\n";
}
} else if (k==3) {
bool ok = true;
minn[0]=t[0];
for(int i = 1;i<n;i++){
minn[i]=min(minn[i-1],t[i]);
}
maxx[n-1]=t[n-1];
for(int i = n-2;i>=0;i--){
maxx[i]=max(maxx[i+1],t[i]);
}
for(int i =1; i<n-1;i++){
if(minn[i-1]>=t[i] || maxx[i+1]<= t[i]) {
cout<<"TAK\n";
cout<<i<<" "<<i+1<<"\n";
ok = false;
break;
}
}
if(ok) {
cout<<"NIE\n";
}
} else if (k==2) {
bool ok = true;
minn[0]=t[0];
for(int i = 1;i<n;i++){
minn[i]=min(minn[i-1],t[i]);
}
maxx[n-1]=t[n-1];
for(int i = n-2;i>=0;i--){
maxx[i]=max(maxx[i+1],t[i]);
}
for(int i =1; i<n;i++){
if(minn[i-1]>=maxx[i]) {
cout<<"TAK\n";
cout<<i<<"\n";
ok = false;
break;
}
}
if(ok) {
cout<<"NIE\n";
}
}
}
int main() {
ios_base::sync_with_stdio(false);
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 | #include <bits/stdc++.h> #include <queue> using namespace std; int n,k; int t[500000]; int minn[500000]; int maxx[500000]; void read() { cin>>n>>k; for(int i =0;i<n;i++){ cin>>t[i]; } } void solve() { read(); if(k>=4){ // szukamy miejsca gdzie t[i-1]>=t[i] bool ok = true; for(int i = 1;i<n;i++){ if(t[i-1]>=t[i]){ cout<<"TAK\n"; //(i-1|i|i+1) int s =0; if(i-1==0)s++; if(i+1==n)s++; k-=3; k+=s; int j = 1; while(j<i-1 && k> 0){ cout<<j<<" "; j++; k--; } if(i-1!=0) cout<<i-1<<" "; cout<<i<<" "; j = i+1; while(j<n && k> 0){ cout<<j<<" "; j++; k--; } ok = false; break; } } if(ok){ cout<<"NIE\n"; } } else if (k==3) { bool ok = true; minn[0]=t[0]; for(int i = 1;i<n;i++){ minn[i]=min(minn[i-1],t[i]); } maxx[n-1]=t[n-1]; for(int i = n-2;i>=0;i--){ maxx[i]=max(maxx[i+1],t[i]); } for(int i =1; i<n-1;i++){ if(minn[i-1]>=t[i] || maxx[i+1]<= t[i]) { cout<<"TAK\n"; cout<<i<<" "<<i+1<<"\n"; ok = false; break; } } if(ok) { cout<<"NIE\n"; } } else if (k==2) { bool ok = true; minn[0]=t[0]; for(int i = 1;i<n;i++){ minn[i]=min(minn[i-1],t[i]); } maxx[n-1]=t[n-1]; for(int i = n-2;i>=0;i--){ maxx[i]=max(maxx[i+1],t[i]); } for(int i =1; i<n;i++){ if(minn[i-1]>=maxx[i]) { cout<<"TAK\n"; cout<<i<<"\n"; ok = false; break; } } if(ok) { cout<<"NIE\n"; } } } int main() { ios_base::sync_with_stdio(false); solve(); return 0; } |
English