#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin>>n>>k; vector<int>a(n); for (auto &i : a) cin>>i; if (k==2) { vector<int>mx(n); mx[n-1]=a[n-1]; for (int i=n-2; i>=0; i--) mx[i]=max(mx[i+1], a[i]); int mn=INT_MAX; for (int i=0; i<n-1; i++) { mn=min(mn, a[i]); if (mn>=mx[i+1]) { cout<<"TAK\n"<<i+1<<"\n"; return 0; } } cout<<"NIE\n"; } else if (k==3) { int mn=*min_element(a.begin(), a.end()); int mx=*max_element(a.begin(), a.end()); if (a.back()==mn) { cout<<"TAK\n"<<n-2<<" "<<n-1<<"\n"; return 0; } for (int i=1; i<n-1; i++) if (a[i]==mn) { cout<<"TAK\n"<<i<<" "<<i+1<<"\n"; return 0; } if (a[0]==mx) { cout<<"TAK\n"<<1<<" "<<2<<"\n"; return 0; } for (int i=1; i<n-1; i++) if (a[i]==mx) { cout<<"TAK\n"<<i<<" "<<i+1<<"\n"; return 0; } cout<<"NIE\n"; } else { for (int i=1; i<n; i++) { if (a[i]<=a[i-1]) { vector<char>u(n+1); k--; if (i>1) u[i-1]=1, k--; u[i]=1, k--; if (i+1<n) u[i+1]=1, k--; //~ cout<<k<<"\n"; cout<<"TAK\n"; for (int j=1; j<n; j++) if (u[j] || k>=1) { if (!u[j]) k--; cout<<j<<" "; } cout<<"\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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin>>n>>k; vector<int>a(n); for (auto &i : a) cin>>i; if (k==2) { vector<int>mx(n); mx[n-1]=a[n-1]; for (int i=n-2; i>=0; i--) mx[i]=max(mx[i+1], a[i]); int mn=INT_MAX; for (int i=0; i<n-1; i++) { mn=min(mn, a[i]); if (mn>=mx[i+1]) { cout<<"TAK\n"<<i+1<<"\n"; return 0; } } cout<<"NIE\n"; } else if (k==3) { int mn=*min_element(a.begin(), a.end()); int mx=*max_element(a.begin(), a.end()); if (a.back()==mn) { cout<<"TAK\n"<<n-2<<" "<<n-1<<"\n"; return 0; } for (int i=1; i<n-1; i++) if (a[i]==mn) { cout<<"TAK\n"<<i<<" "<<i+1<<"\n"; return 0; } if (a[0]==mx) { cout<<"TAK\n"<<1<<" "<<2<<"\n"; return 0; } for (int i=1; i<n-1; i++) if (a[i]==mx) { cout<<"TAK\n"<<i<<" "<<i+1<<"\n"; return 0; } cout<<"NIE\n"; } else { for (int i=1; i<n; i++) { if (a[i]<=a[i-1]) { vector<char>u(n+1); k--; if (i>1) u[i-1]=1, k--; u[i]=1, k--; if (i+1<n) u[i+1]=1, k--; //~ cout<<k<<"\n"; cout<<"TAK\n"; for (int j=1; j<n; j++) if (u[j] || k>=1) { if (!u[j]) k--; cout<<j<<" "; } cout<<"\n"; return 0; } } cout<<"NIE\n"; } return 0; } |