#include <bits/stdc++.h> using namespace std; const int r = 5e5 + 9; int tab[r]; int ma[r]; int mi[r]; bool zap[r]; int main() { ios_base::sync_with_stdio(0);cin.tie(0); int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> tab[i]; if(k == 2) { mi[1] = tab[1]; ma[n] = tab[n]; for(int i = 2; i <= n; i++) mi[i] = min(mi[i - 1], tab[i]); for(int i = n - 1; i >= 1; i--) ma[i] = max(ma[i + 1], tab[i]); for(int i = 1; i <= n - 1; i++) if(mi[i] >= ma[i + 1]) { cout << "TAK\n" << i; return 0; } cout << "NIE\n"; return 0; } if(k == 3) { int minw = tab[1], maxw = tab[1], minp = 1, maxp = 1; for(int i = 2; i <= n; i++) { if(tab[i] <= minw) { minw = tab[i]; minp = i; } if(tab[i] > maxw) { maxw = tab[i]; maxp = i; } } if(minp != 1) { if(minp != n) cout << "TAK\n" << minp - 1 << " " << minp; else cout << "TAK\n" << 1 << " " << minp - 1; } else if(maxp != n) { cout << "TAK\n" << maxp - 1 << " " << maxp; } else { cout << "NIE\n"; return 0; } return 0; } int poz = -1; for(int i = 1; i <= n - 1; i++) if(tab[i] >= tab[i + 1]) poz = i; if(poz == -1) { cout << "NIE\n"; return 0; } int cnt = 3; zap[poz - 1] = zap[poz] = zap[poz + 1] = 1; if(poz + 1 == n) { cnt --; zap[n] = 0; } int w = 1; while(cnt < k - 1) { if(!zap[w]) { cnt ++; zap[w] = 1; } w ++; } cout << "TAK\n"; for(int i = 1; i <= n; i++) { if(zap[i]) cout << i << " "; } }
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 | #include <bits/stdc++.h> using namespace std; const int r = 5e5 + 9; int tab[r]; int ma[r]; int mi[r]; bool zap[r]; int main() { ios_base::sync_with_stdio(0);cin.tie(0); int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> tab[i]; if(k == 2) { mi[1] = tab[1]; ma[n] = tab[n]; for(int i = 2; i <= n; i++) mi[i] = min(mi[i - 1], tab[i]); for(int i = n - 1; i >= 1; i--) ma[i] = max(ma[i + 1], tab[i]); for(int i = 1; i <= n - 1; i++) if(mi[i] >= ma[i + 1]) { cout << "TAK\n" << i; return 0; } cout << "NIE\n"; return 0; } if(k == 3) { int minw = tab[1], maxw = tab[1], minp = 1, maxp = 1; for(int i = 2; i <= n; i++) { if(tab[i] <= minw) { minw = tab[i]; minp = i; } if(tab[i] > maxw) { maxw = tab[i]; maxp = i; } } if(minp != 1) { if(minp != n) cout << "TAK\n" << minp - 1 << " " << minp; else cout << "TAK\n" << 1 << " " << minp - 1; } else if(maxp != n) { cout << "TAK\n" << maxp - 1 << " " << maxp; } else { cout << "NIE\n"; return 0; } return 0; } int poz = -1; for(int i = 1; i <= n - 1; i++) if(tab[i] >= tab[i + 1]) poz = i; if(poz == -1) { cout << "NIE\n"; return 0; } int cnt = 3; zap[poz - 1] = zap[poz] = zap[poz + 1] = 1; if(poz + 1 == n) { cnt --; zap[n] = 0; } int w = 1; while(cnt < k - 1) { if(!zap[w]) { cnt ++; zap[w] = 1; } w ++; } cout << "TAK\n"; for(int i = 1; i <= n; i++) { if(zap[i]) cout << i << " "; } } |