#include <bits/stdc++.h> using namespace std; int tab[500100]; int n,k; bool dwojka(){ int mini[n]; int maks[n]; mini[0] = tab[0]; maks[n-1] = tab[n-1]; for(int i=1;i<n;i++)mini[i] = min(mini[i-1], tab[i]); for(int i=n-2;i>=0;i--)maks[i] = max(maks[i+1], tab[i]); for(int i=0;i<n-1;i++){ if(mini[i] >= maks[i+1]){ cout<<"TAK"<<endl; cout<<i+1<<endl; return true; } } cout<<"NIE"<<endl; return false; } bool trojka(){ int najw = -1000000100; int najmn = 1000000100; for(int i=0;i<n;i++){ najw = max(najw, tab[i]); najmn = min(najmn, tab[i]); } for(int i=1;i<n-1;i++){ if(tab[i] == najw || tab[i] == najmn){ cout<<"TAK"<<endl; cout<<i<<" "<<i+1<<endl; return true; } } if(tab[0]==najw){ cout<<"TAK"<<endl; cout<<1<<" "<<2<<endl; return true; } if(tab[n-1]==najmn){ cout<<"TAK"<<endl; cout<<n-2<<" "<<n-1<<endl; return true; } cout<<"NIE"<<endl; return false; } bool reszta(){ for(int i=0;i<n-1;i++){ if(tab[i] >= tab[i+1]){ cout<<"TAK"<<endl; if(i==n-2){ for(int j=n-k+1;j<n;j++){cout<<j<<" ";} } else{//na pewno konce w i, i+1 oraz i+2 if(i-1 >= k-4){ for(int j=1;j<=k-4;j++)cout<<j<<" "; cout<<i<<" "<<i+1<<" "<<i+2; } else{ int kon = k-4-i+1; for(int j=1;j<=i-1;j++)cout<<j<<" "; cout<<i<<" "<<i+1<<" "<<i+2<<" "; for(int j=i+3;j<=i+2+kon;j++)cout<<j<<" "; } } cout<<endl; return true; } } cout<<"NIE"<<endl; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=0;i<n;i++)cin>>tab[i]; int odwr[n]; for(int i=0;i<n;i++)odwr[i] = -tab[n-1-i]; if(k==2){ dwojka(); return 0; } if(k==3){ trojka(); return 0; } reszta(); 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 | #include <bits/stdc++.h> using namespace std; int tab[500100]; int n,k; bool dwojka(){ int mini[n]; int maks[n]; mini[0] = tab[0]; maks[n-1] = tab[n-1]; for(int i=1;i<n;i++)mini[i] = min(mini[i-1], tab[i]); for(int i=n-2;i>=0;i--)maks[i] = max(maks[i+1], tab[i]); for(int i=0;i<n-1;i++){ if(mini[i] >= maks[i+1]){ cout<<"TAK"<<endl; cout<<i+1<<endl; return true; } } cout<<"NIE"<<endl; return false; } bool trojka(){ int najw = -1000000100; int najmn = 1000000100; for(int i=0;i<n;i++){ najw = max(najw, tab[i]); najmn = min(najmn, tab[i]); } for(int i=1;i<n-1;i++){ if(tab[i] == najw || tab[i] == najmn){ cout<<"TAK"<<endl; cout<<i<<" "<<i+1<<endl; return true; } } if(tab[0]==najw){ cout<<"TAK"<<endl; cout<<1<<" "<<2<<endl; return true; } if(tab[n-1]==najmn){ cout<<"TAK"<<endl; cout<<n-2<<" "<<n-1<<endl; return true; } cout<<"NIE"<<endl; return false; } bool reszta(){ for(int i=0;i<n-1;i++){ if(tab[i] >= tab[i+1]){ cout<<"TAK"<<endl; if(i==n-2){ for(int j=n-k+1;j<n;j++){cout<<j<<" ";} } else{//na pewno konce w i, i+1 oraz i+2 if(i-1 >= k-4){ for(int j=1;j<=k-4;j++)cout<<j<<" "; cout<<i<<" "<<i+1<<" "<<i+2; } else{ int kon = k-4-i+1; for(int j=1;j<=i-1;j++)cout<<j<<" "; cout<<i<<" "<<i+1<<" "<<i+2<<" "; for(int j=i+3;j<=i+2+kon;j++)cout<<j<<" "; } } cout<<endl; return true; } } cout<<"NIE"<<endl; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=0;i<n;i++)cin>>tab[i]; int odwr[n]; for(int i=0;i<n;i++)odwr[i] = -tab[n-1-i]; if(k==2){ dwojka(); return 0; } if(k==3){ trojka(); return 0; } reszta(); return 0; } |