#include <bits/stdc++.h>
using namespace std;
int tab[500001];
bool wyp[500001];
int mado[500001];
int miod[500001];
int main(){ios_base::sync_with_stdio(0);cin.tie();
int n,k;
bool czy=0;
cin >> n >> k;
for(int i=0;i<n;i++){
cin >> tab[i];
}
if(k>=4){
for(int i=1;i<n;i++){
if(tab[i]<=tab[i-1] && czy==0){
wyp[i]=1;
wyp[i-1]=1;
czy=1;
//cerr << i << ' ' << i-1 << '\n';
}
}
if(czy==0){
cout << "NIE";
return 0;
}else{
cout << "TAK" << '\n';
int ile=k-3;
for(int i=0;i<n;i++){
if(wyp[i]==0 && ile>0){
wyp[i]=1;
ile--;
}
if(wyp[i]==1){
cout << i+1 << ' ';
}
}
}
}
else if(k==2){
int l=0;
int p=n;
miod[0]=tab[0];
for(int i=1;i<n;i++){
miod[i]=min(tab[i],miod[i-1]);
}
mado[n-1]=tab[n-1];
for(int i=n-2;i>=0;i--){
mado[i]=max(mado[i+1],tab[i]);
}
for(int i=0;i<n-1;i++){
if(miod[i]>mado[i+1]){
cout << "TAK" << '\n' << i+1;
return 0;
}
}
cout << "NIE";
}else{
int mak=0;
int curmi=0;
int curma=0;
int mio=2137213722;
for(int i=0;i<n;i++){
if(tab[i]<mio){
mio=tab[i];
curmi=i;
}
if(tab[i]>mak){
mak=tab[i];
curma=i;
}
}
if(curma!=0 && curma!=n-1){
cout << "TAK" << '\n' << curma << ' ' << curma+1;
return 0;
}
if(curmi!=0 && curmi!=n-1){
cout << "TAK" << '\n' << curmi << ' ' << curmi+1;
return 0;
}
cout << "NIE";
}
}
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 | #include <bits/stdc++.h> using namespace std; int tab[500001]; bool wyp[500001]; int mado[500001]; int miod[500001]; int main(){ios_base::sync_with_stdio(0);cin.tie(); int n,k; bool czy=0; cin >> n >> k; for(int i=0;i<n;i++){ cin >> tab[i]; } if(k>=4){ for(int i=1;i<n;i++){ if(tab[i]<=tab[i-1] && czy==0){ wyp[i]=1; wyp[i-1]=1; czy=1; //cerr << i << ' ' << i-1 << '\n'; } } if(czy==0){ cout << "NIE"; return 0; }else{ cout << "TAK" << '\n'; int ile=k-3; for(int i=0;i<n;i++){ if(wyp[i]==0 && ile>0){ wyp[i]=1; ile--; } if(wyp[i]==1){ cout << i+1 << ' '; } } } } else if(k==2){ int l=0; int p=n; miod[0]=tab[0]; for(int i=1;i<n;i++){ miod[i]=min(tab[i],miod[i-1]); } mado[n-1]=tab[n-1]; for(int i=n-2;i>=0;i--){ mado[i]=max(mado[i+1],tab[i]); } for(int i=0;i<n-1;i++){ if(miod[i]>mado[i+1]){ cout << "TAK" << '\n' << i+1; return 0; } } cout << "NIE"; }else{ int mak=0; int curmi=0; int curma=0; int mio=2137213722; for(int i=0;i<n;i++){ if(tab[i]<mio){ mio=tab[i]; curmi=i; } if(tab[i]>mak){ mak=tab[i]; curma=i; } } if(curma!=0 && curma!=n-1){ cout << "TAK" << '\n' << curma << ' ' << curma+1; return 0; } if(curmi!=0 && curmi!=n-1){ cout << "TAK" << '\n' << curmi << ' ' << curmi+1; return 0; } cout << "NIE"; } } |
English