#include <cstdio> #include <vector> #include <algorithm> #include <set> using namespace std; int main () { int n, k; scanf("%d %d", &n, &k); vector<int> data; data.reserve(n + 8); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); data.push_back(x); } bool sorted = true; for (int i = 1; i < n; ++i) { if (data[i - 1] >= data[i]) { sorted = false; } } if (sorted) { printf("NIE\n"); return 0; } bool constant = true; for (int i = 1; i < n; ++i) { if (data[i - 1] != data[i]) { constant = false; break; } } if (constant) { printf("TAK\n"); for (int i = 0; i < k; ++i) { printf(i == k - 1 ? "%d\n" : "%d ", i + 1); } return 0; } if (k >= 4) { for (int i = 1; i < n; ++i) { if (data[i - 1] < data[i]) { continue; } set<int> res; if (i >= 2) { res.insert(i - 2); } res.insert(i - 1); if (i < n - 1) { res.insert(i); } for (int j = 0; j < n; ++j) { if (res.size() == k - 1) { break; } if (res.find(j) == res.end()) { res.insert(j); } } vector<int> ress; for (set<int>::iterator it = res.begin(); it != res.end(); it++) { ress.push_back(*it); } sort(ress.begin(), ress.end()); printf("TAK\n"); for (int i = 0; i < ress.size(); ++i) { printf(i == ress.size() - 1 ? "%d\n" : "%d ", ress[i] + 1); } return 0; } } if (k == 2) { vector<int> lmins; int lmin = data[0]; for (int i = 0; i < n; ++i) { if (data[i] < lmin) { lmin = data[i]; } lmins.push_back(lmin); } vector<int> rmaxs(n, 0); int rmax = data[n - 1]; for (int i = n - 1; i >= 0; --i) { if (data[i] > rmax) { rmax = data[i]; } rmaxs[i] = rmax; } for (int i = 0; i < n - 1; ++i) { if (lmins[i] >= rmaxs[i + 1]) { printf("TAK\n%d\n", i + 1); return 0; } } printf("NIE\n"); return 0; } int maxn = data[0]; for (int i = 0; i < n; ++i) { if (data[i] > maxn) { maxn = data[i]; } } vector<int> max_idxs; for (int i = 0; i < n; ++i) { if (data[i] == maxn) { max_idxs.push_back(i); } } int minn = data[0]; for (int i = 0; i < n; ++i) { if (data[i] < minn) { minn = data[i]; } } vector<int> min_idxs; for (int i = 0; i < n; ++i) { if (data[i] == minn) { min_idxs.push_back(i); } } int last_min = min_idxs[min_idxs.size() - 1]; if (last_min != 0) { printf("TAK\n"); if (last_min == n - 1) { printf("%d %d\n", n - 2, n - 1); } else { printf("%d %d\n", last_min, last_min + 1); } return 0; } int first_max = max_idxs[0]; if (first_max != n - 1) { printf("TAK\n"); if (first_max == 0) { printf("%d %d\n", 1, 2); } else { printf("%d %d\n", first_max, first_max + 1); } return 0; } printf("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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | #include <cstdio> #include <vector> #include <algorithm> #include <set> using namespace std; int main () { int n, k; scanf("%d %d", &n, &k); vector<int> data; data.reserve(n + 8); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); data.push_back(x); } bool sorted = true; for (int i = 1; i < n; ++i) { if (data[i - 1] >= data[i]) { sorted = false; } } if (sorted) { printf("NIE\n"); return 0; } bool constant = true; for (int i = 1; i < n; ++i) { if (data[i - 1] != data[i]) { constant = false; break; } } if (constant) { printf("TAK\n"); for (int i = 0; i < k; ++i) { printf(i == k - 1 ? "%d\n" : "%d ", i + 1); } return 0; } if (k >= 4) { for (int i = 1; i < n; ++i) { if (data[i - 1] < data[i]) { continue; } set<int> res; if (i >= 2) { res.insert(i - 2); } res.insert(i - 1); if (i < n - 1) { res.insert(i); } for (int j = 0; j < n; ++j) { if (res.size() == k - 1) { break; } if (res.find(j) == res.end()) { res.insert(j); } } vector<int> ress; for (set<int>::iterator it = res.begin(); it != res.end(); it++) { ress.push_back(*it); } sort(ress.begin(), ress.end()); printf("TAK\n"); for (int i = 0; i < ress.size(); ++i) { printf(i == ress.size() - 1 ? "%d\n" : "%d ", ress[i] + 1); } return 0; } } if (k == 2) { vector<int> lmins; int lmin = data[0]; for (int i = 0; i < n; ++i) { if (data[i] < lmin) { lmin = data[i]; } lmins.push_back(lmin); } vector<int> rmaxs(n, 0); int rmax = data[n - 1]; for (int i = n - 1; i >= 0; --i) { if (data[i] > rmax) { rmax = data[i]; } rmaxs[i] = rmax; } for (int i = 0; i < n - 1; ++i) { if (lmins[i] >= rmaxs[i + 1]) { printf("TAK\n%d\n", i + 1); return 0; } } printf("NIE\n"); return 0; } int maxn = data[0]; for (int i = 0; i < n; ++i) { if (data[i] > maxn) { maxn = data[i]; } } vector<int> max_idxs; for (int i = 0; i < n; ++i) { if (data[i] == maxn) { max_idxs.push_back(i); } } int minn = data[0]; for (int i = 0; i < n; ++i) { if (data[i] < minn) { minn = data[i]; } } vector<int> min_idxs; for (int i = 0; i < n; ++i) { if (data[i] == minn) { min_idxs.push_back(i); } } int last_min = min_idxs[min_idxs.size() - 1]; if (last_min != 0) { printf("TAK\n"); if (last_min == n - 1) { printf("%d %d\n", n - 2, n - 1); } else { printf("%d %d\n", last_min, last_min + 1); } return 0; } int first_max = max_idxs[0]; if (first_max != n - 1) { printf("TAK\n"); if (first_max == 0) { printf("%d %d\n", 1, 2); } else { printf("%d %d\n", first_max, first_max + 1); } return 0; } printf("NIE\n"); return 0; } |