#include<bits/stdc++.h> #define ll long long using namespace std; const int N=5e5+5; bool mark[N]; int n,k,a[N],mn[N],mx[N]; bool check() { for (int i=1;i<n;i++) { if (a[i]>a[i+1]) { return 0; } } return 1; } signed main() { ios::sync_with_stdio(false),cin.tie(0); cout.precision(10),cout.setf(ios::fixed); cin>>n>>k; for (int i=1;i<=n;i++) { cin>>a[i]; } if (check()) { cout<<"NIE\n"; return 0; } if (k>=4) { for (int i=1;i<n;i++) { if (a[i]>a[i+1]) { mark[i]=mark[i+1]=1; break; } } int m=k-3; for (int i=1;i<=n;i++) { if (m&&!mark[i]) { mark[i]=1; m--; } } cout<<"TAK\n"; for (int i=1;i<=n;i++) { if (mark[i]) { cout<<i<<" "; } } } else { mn[0]=1e9+7,mx[n+1]=0; for (int i=1;i<=n;i++) { mn[i]=min(mn[i-1],a[i]); } for (int i=n;i>=1;i--) { mx[i]=max(mx[i+1],a[i]); } if (k==2) { for (int i=1;i<n;i++) { if (mn[i]>mx[i+1]) { cout<<"TAK\n"<<i<<"\n"; return 0; } } cout<<"NIE\n"; } else { if (a[1]!=mn[n]) { for (int i=1;i<=n;i++) { if (a[i]==mn[n]) { cout<<"TAK\n"<<i-1<<' '<<i<<"\n"; return 0; } } } if (a[n]!=mx[1]) { for (int i=1;i<=n;i++) { if (a[i]==mx[1]) { cout<<"TAK\n"<<i-1<<' '<<i<<"\n"; return 0; } } } cout<<"NIE\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 81 82 83 84 85 86 87 | #include<bits/stdc++.h> #define ll long long using namespace std; const int N=5e5+5; bool mark[N]; int n,k,a[N],mn[N],mx[N]; bool check() { for (int i=1;i<n;i++) { if (a[i]>a[i+1]) { return 0; } } return 1; } signed main() { ios::sync_with_stdio(false),cin.tie(0); cout.precision(10),cout.setf(ios::fixed); cin>>n>>k; for (int i=1;i<=n;i++) { cin>>a[i]; } if (check()) { cout<<"NIE\n"; return 0; } if (k>=4) { for (int i=1;i<n;i++) { if (a[i]>a[i+1]) { mark[i]=mark[i+1]=1; break; } } int m=k-3; for (int i=1;i<=n;i++) { if (m&&!mark[i]) { mark[i]=1; m--; } } cout<<"TAK\n"; for (int i=1;i<=n;i++) { if (mark[i]) { cout<<i<<" "; } } } else { mn[0]=1e9+7,mx[n+1]=0; for (int i=1;i<=n;i++) { mn[i]=min(mn[i-1],a[i]); } for (int i=n;i>=1;i--) { mx[i]=max(mx[i+1],a[i]); } if (k==2) { for (int i=1;i<n;i++) { if (mn[i]>mx[i+1]) { cout<<"TAK\n"<<i<<"\n"; return 0; } } cout<<"NIE\n"; } else { if (a[1]!=mn[n]) { for (int i=1;i<=n;i++) { if (a[i]==mn[n]) { cout<<"TAK\n"<<i-1<<' '<<i<<"\n"; return 0; } } } if (a[n]!=mx[1]) { for (int i=1;i<=n;i++) { if (a[i]==mx[1]) { cout<<"TAK\n"<<i-1<<' '<<i<<"\n"; return 0; } } } cout<<"NIE\n"; } } return 0; } |