#if defined(EMBE_DEBUG) && !defined(NDEBUG) #include "embe-debug.hpp" #else #define LOG_INDENT(...) do {} while (false) #define LOG(...) do {} while (false) #define DUMP(...) do {} while (false) #endif #include <algorithm> #include <climits> #include <iostream> #include <optional> #include <set> #include <vector> using namespace std; namespace { optional<set<int>> repair(set<int> input, int n, int k) { input.erase(0); input.erase(n); if (int(input.size()) >= k) return nullopt; int i = 0; while (int(input.size()) < k - 1) input.insert(i), ++i; return input; } optional<set<int>> solve_(vector<int> data, int k) { int n = data.size(); optional<set<int>> res = nullopt; auto first_ge = adjacent_find(data.begin(), data.end(), [](auto const& a, auto const& b) { return a >= b; }); if (first_ge == data.end()) { return res; } int m = *min_element(data.begin(), data.end()); int M = *max_element(data.begin(), data.end()); for (int i = 0; i < n; ++i) { if ((i > 0 && data[i] == m) || (i < n - 1 && data[i] == M)) { res = repair({i, i+1}, n, k); if (res) return res; } } int f = first_ge - data.begin(); res = repair({f, f + 1, f + 2}, n, k); if (res) return res; if (data[n - 2] >= data[n - 1]) { res = repair({n - 2, n - 1, n}, n, k); if (res) return res; } vector<int> min_left = {INT_MAX}; for (int x: data) { min_left.push_back(min(min_left.back(), x)); } vector<int> max_right = {INT_MIN}; reverse(data.begin(), data.end()); for (int x: data) { max_right.push_back(max(max_right.back(), x)); } for (int i = 1; i < n; ++i) { if (min_left[i] >= max_right[n - i]) { res = repair({i}, n, k); if (res) return res; } } return res; } optional<set<int>> solve(vector<int> data, int k) { auto res = solve_(move(data), k); if (res) { } return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> data(n); for (int& x: data) { cin >> x; } auto res = solve(move(data), k); if (res) { cout << "TAK\n"; bool first = true; for (int x: *res) { if (first) first = false; else cout << ' '; cout << x; } cout << '\n'; } else { 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 102 103 104 105 106 107 | #if defined(EMBE_DEBUG) && !defined(NDEBUG) #include "embe-debug.hpp" #else #define LOG_INDENT(...) do {} while (false) #define LOG(...) do {} while (false) #define DUMP(...) do {} while (false) #endif #include <algorithm> #include <climits> #include <iostream> #include <optional> #include <set> #include <vector> using namespace std; namespace { optional<set<int>> repair(set<int> input, int n, int k) { input.erase(0); input.erase(n); if (int(input.size()) >= k) return nullopt; int i = 0; while (int(input.size()) < k - 1) input.insert(i), ++i; return input; } optional<set<int>> solve_(vector<int> data, int k) { int n = data.size(); optional<set<int>> res = nullopt; auto first_ge = adjacent_find(data.begin(), data.end(), [](auto const& a, auto const& b) { return a >= b; }); if (first_ge == data.end()) { return res; } int m = *min_element(data.begin(), data.end()); int M = *max_element(data.begin(), data.end()); for (int i = 0; i < n; ++i) { if ((i > 0 && data[i] == m) || (i < n - 1 && data[i] == M)) { res = repair({i, i+1}, n, k); if (res) return res; } } int f = first_ge - data.begin(); res = repair({f, f + 1, f + 2}, n, k); if (res) return res; if (data[n - 2] >= data[n - 1]) { res = repair({n - 2, n - 1, n}, n, k); if (res) return res; } vector<int> min_left = {INT_MAX}; for (int x: data) { min_left.push_back(min(min_left.back(), x)); } vector<int> max_right = {INT_MIN}; reverse(data.begin(), data.end()); for (int x: data) { max_right.push_back(max(max_right.back(), x)); } for (int i = 1; i < n; ++i) { if (min_left[i] >= max_right[n - i]) { res = repair({i}, n, k); if (res) return res; } } return res; } optional<set<int>> solve(vector<int> data, int k) { auto res = solve_(move(data), k); if (res) { } return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> data(n); for (int& x: data) { cin >> x; } auto res = solve(move(data), k); if (res) { cout << "TAK\n"; bool first = true; for (int x: *res) { if (first) first = false; else cout << ' '; cout << x; } cout << '\n'; } else { cout << "NIE\n"; } return 0; } |