#include <bits/stdc++.h> using namespace std; #define MAX_N 500007 int n, k, f, s, minpos, maxpos; int t[MAX_N]; bool found = false; int minx = INT_MAX; int maxx = -1; int localmax[MAX_N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; cin >> t[1]; for (int i = 2; i <= n; i++) { cin >> t[i]; if(t[i] <= t[i - 1]) { f = i - 1; s = i; found = true; } } if (!found) { cout << "NIE\n"; return 0; } if (k > 3) { k -= 4; if (s == n) { k++; } cout << "TAK\n"; for (int i = 1; i < n; i++) { if (i == f - 1 || i == f || i == s) { cout << i << " "; } else if (k > 0) { cout << i << " "; k--; } } return 0; } if (k == 3) { for (int i = 1; i <= n; i++) { if (t[i] <= minx) { minx = t[i]; minpos = i; } if (t[i] > maxx) { maxx = t[i]; maxpos = i; } } if (maxpos < n) { cout << "TAK\n"; if (maxpos == 1) { cout << 1 << " " << 2; } else { cout << maxpos - 1 << " " << maxpos; } } else if (minpos > 1) { cout << "TAK\n"; if (minpos == n) { cout << n-2 << " " << n-1; } else { cout << minpos - 1 << " " << minpos; } } else { cout << "NIE\n"; } return 0; } if (k == 2) { for (int i = n; i >= 1; i--) { if (t[i] > maxx) { maxx = t[i]; localmax[i] = maxx; } else { localmax[i] = localmax[i+1]; } } for (int i = 1; i < n; i++) { if (t[i] < minx) { minx = t[i]; } if (minx > localmax[i+1]) { cout << "TAK\n" << i; 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #include <bits/stdc++.h> using namespace std; #define MAX_N 500007 int n, k, f, s, minpos, maxpos; int t[MAX_N]; bool found = false; int minx = INT_MAX; int maxx = -1; int localmax[MAX_N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; cin >> t[1]; for (int i = 2; i <= n; i++) { cin >> t[i]; if(t[i] <= t[i - 1]) { f = i - 1; s = i; found = true; } } if (!found) { cout << "NIE\n"; return 0; } if (k > 3) { k -= 4; if (s == n) { k++; } cout << "TAK\n"; for (int i = 1; i < n; i++) { if (i == f - 1 || i == f || i == s) { cout << i << " "; } else if (k > 0) { cout << i << " "; k--; } } return 0; } if (k == 3) { for (int i = 1; i <= n; i++) { if (t[i] <= minx) { minx = t[i]; minpos = i; } if (t[i] > maxx) { maxx = t[i]; maxpos = i; } } if (maxpos < n) { cout << "TAK\n"; if (maxpos == 1) { cout << 1 << " " << 2; } else { cout << maxpos - 1 << " " << maxpos; } } else if (minpos > 1) { cout << "TAK\n"; if (minpos == n) { cout << n-2 << " " << n-1; } else { cout << minpos - 1 << " " << minpos; } } else { cout << "NIE\n"; } return 0; } if (k == 2) { for (int i = n; i >= 1; i--) { if (t[i] > maxx) { maxx = t[i]; localmax[i] = maxx; } else { localmax[i] = localmax[i+1]; } } for (int i = 1; i < n; i++) { if (t[i] < minx) { minx = t[i]; } if (minx > localmax[i+1]) { cout << "TAK\n" << i; return 0; } } cout << "NIE\n"; return 0; } } |