#include <bits/stdc++.h> using namespace std; const int MAXN = 1000006; int n, k; int t[MAXN]; int prefMin[MAXN]; int sufMax[MAXN]; bool IsStrictlyIncreasing() { for (int i = 1; i <= n; ++i) { if (t[i - 1] >= t[i]) { return false; } } return true; } vector<int> SolveK2() { for (int i = 1; i < n; ++i) { if (prefMin[i] >= sufMax[i + 1]) { return {i}; } } return {}; } vector<int> Solve() { vector<int> res; int inversion = 0; for (int i = 2; i <= n; ++i) { if (t[i - 1] >= t[i]) { inversion = i; res.push_back(i); res.push_back(i - 1); if (i - 2 >= 1) { res.push_back(i - 2); } break; } } int toCreate = k - res.size() - 1; for (int i = inversion + 1; i <= n; ++i) { if (toCreate == 0) { break; } --toCreate; res.push_back(i); } for (int i = 1; i < inversion - 2; ++i) { if (toCreate == 0) { break; } --toCreate; res.push_back(i); } sort(res.begin(), res.end()); return res; } vector<int> SolveK3() { for (int i = 2; i < n; ++i) { if (prefMin[i - 1] >= t[i] || t[i] >= sufMax[i + 1]) { return {i - 1, i}; } } return {}; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) { scanf("%d", &t[i]); } if (IsStrictlyIncreasing()) { printf("NIE\n"); return 0; } prefMin[1] = t[1]; for (int i = 2; i <= n; ++i) { prefMin[i] = min(prefMin[i - 1], t[i]); } sufMax[n] = t[n]; for (int i = n - 1; i >= 1; --i) { sufMax[i] = max(sufMax[i + 1], t[i]); } vector<int> res; if (k == 2) { res = SolveK2(); } else if (k == 3) { res = SolveK3(); } else { res = Solve(); } if (res.empty()) { printf("NIE\n"); return 0; } printf("TAK\n"); for (auto x : res) { printf("%d ", x); } }
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 | #include <bits/stdc++.h> using namespace std; const int MAXN = 1000006; int n, k; int t[MAXN]; int prefMin[MAXN]; int sufMax[MAXN]; bool IsStrictlyIncreasing() { for (int i = 1; i <= n; ++i) { if (t[i - 1] >= t[i]) { return false; } } return true; } vector<int> SolveK2() { for (int i = 1; i < n; ++i) { if (prefMin[i] >= sufMax[i + 1]) { return {i}; } } return {}; } vector<int> Solve() { vector<int> res; int inversion = 0; for (int i = 2; i <= n; ++i) { if (t[i - 1] >= t[i]) { inversion = i; res.push_back(i); res.push_back(i - 1); if (i - 2 >= 1) { res.push_back(i - 2); } break; } } int toCreate = k - res.size() - 1; for (int i = inversion + 1; i <= n; ++i) { if (toCreate == 0) { break; } --toCreate; res.push_back(i); } for (int i = 1; i < inversion - 2; ++i) { if (toCreate == 0) { break; } --toCreate; res.push_back(i); } sort(res.begin(), res.end()); return res; } vector<int> SolveK3() { for (int i = 2; i < n; ++i) { if (prefMin[i - 1] >= t[i] || t[i] >= sufMax[i + 1]) { return {i - 1, i}; } } return {}; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) { scanf("%d", &t[i]); } if (IsStrictlyIncreasing()) { printf("NIE\n"); return 0; } prefMin[1] = t[1]; for (int i = 2; i <= n; ++i) { prefMin[i] = min(prefMin[i - 1], t[i]); } sufMax[n] = t[n]; for (int i = n - 1; i >= 1; --i) { sufMax[i] = max(sufMax[i + 1], t[i]); } vector<int> res; if (k == 2) { res = SolveK2(); } else if (k == 3) { res = SolveK3(); } else { res = Solve(); } if (res.empty()) { printf("NIE\n"); return 0; } printf("TAK\n"); for (auto x : res) { printf("%d ", x); } } |