#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5+7; int n, k, a, b=0, mi, tab[MAX_N], ok=0, ma[MAX_N], mn[MAX_N]; vector<int> vec; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>k; if (k>=4) { cin>>tab[0]; for (int i = 1; i < n; i++) { cin>>tab[i]; if (tab[i-1] >= tab[i] && ok==0) { if (i-1!=0) { vec.push_back(i-1); b++; } vec.push_back(i); b++; if (i+1!=n) { vec.push_back(i+1); b++; } a=i; ok=1; } } if (ok==0) { cout<<"NIE"; return 0; } else { cout<<"TAK\n"; for (int i = 1; i < n-1; i++) { if (i == a-1) { i+=2; continue; } if (i == a) { i+=1; continue; } if (b < k-1) { vec.push_back(i); b++; } else break; } sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++) { cout<<vec[i]<<" "; } } } else if (k == 3) { for (int i = 0; i < n; i++) { cin>>tab[i]; } mn[0] = tab[0]; ma[n-1] = tab[n-1]; for (int i = 1; i < n; i++) { mn[i] = min(mn[i-1], tab[i]); ma[n-i-1] = max(ma[n-i], tab[n-i-1]); } for (int i = 1; i < n; i++) { if (tab[i] <= mn[i-1]) { cout<<"TAK\n"; if (i+1!=n) cout<<i<<" "<<i+1; else cout<<1<<" "<<i; return 0; } if (tab[i-1] >= ma[i]) { cout<<"TAK\n"; if (i-1!=0) cout<<i-1<<" "<<i; else cout<<i<<" "<<n-1; return 0; } } cout<<"NIE"; } else if (k==2) { for (int i = 0; i < n; i++) { cin>>tab[i]; } mn[0] = tab[0]; ma[n-1] = tab[n-1]; for (int i = 1; i < n; i++) { mn[i] = min(mn[i-1], tab[i]); ma[n-i-1] = max(ma[n-i], tab[n-i-1]); } for (int i = 1; i < n; i++) { if (mn[i-1] >= ma[i]) { cout<<"TAK\n"; cout<<i+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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5+7; int n, k, a, b=0, mi, tab[MAX_N], ok=0, ma[MAX_N], mn[MAX_N]; vector<int> vec; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>k; if (k>=4) { cin>>tab[0]; for (int i = 1; i < n; i++) { cin>>tab[i]; if (tab[i-1] >= tab[i] && ok==0) { if (i-1!=0) { vec.push_back(i-1); b++; } vec.push_back(i); b++; if (i+1!=n) { vec.push_back(i+1); b++; } a=i; ok=1; } } if (ok==0) { cout<<"NIE"; return 0; } else { cout<<"TAK\n"; for (int i = 1; i < n-1; i++) { if (i == a-1) { i+=2; continue; } if (i == a) { i+=1; continue; } if (b < k-1) { vec.push_back(i); b++; } else break; } sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++) { cout<<vec[i]<<" "; } } } else if (k == 3) { for (int i = 0; i < n; i++) { cin>>tab[i]; } mn[0] = tab[0]; ma[n-1] = tab[n-1]; for (int i = 1; i < n; i++) { mn[i] = min(mn[i-1], tab[i]); ma[n-i-1] = max(ma[n-i], tab[n-i-1]); } for (int i = 1; i < n; i++) { if (tab[i] <= mn[i-1]) { cout<<"TAK\n"; if (i+1!=n) cout<<i<<" "<<i+1; else cout<<1<<" "<<i; return 0; } if (tab[i-1] >= ma[i]) { cout<<"TAK\n"; if (i-1!=0) cout<<i-1<<" "<<i; else cout<<i<<" "<<n-1; return 0; } } cout<<"NIE"; } else if (k==2) { for (int i = 0; i < n; i++) { cin>>tab[i]; } mn[0] = tab[0]; ma[n-1] = tab[n-1]; for (int i = 1; i < n; i++) { mn[i] = min(mn[i-1], tab[i]); ma[n-i-1] = max(ma[n-i], tab[n-i-1]); } for (int i = 1; i < n; i++) { if (mn[i-1] >= ma[i]) { cout<<"TAK\n"; cout<<i+1; return 0; } } cout<<"NIE"; } } |