#include <bits/stdc++.h> using namespace std; constexpr int INF = 1'000'000'001; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> min_pref(n + 1, INF), max_suff(n + 2); for (int i = 1; i <= n; i++) { min_pref[i] = min(min_pref[i - 1], a[i]); } for (int i = n; i >= 1; i--) { max_suff[i] = max(max_suff[i + 1], a[i]); } vector<int> result; if (k == 2) { for (int i = 1; i < n; i++) { if (min_pref[i] >= max_suff[i + 1]) { result.emplace_back(i); break; } } } else if (k == 3) { if (a[1] >= a[n]) { result.emplace_back(1); result.emplace_back(n - 1); } else { for (int i = 2; i <= n - 1; i++) { if (a[1] >= a[i]) { result.emplace_back(i - 1); result.emplace_back(i); break; } } if (result.empty()) { for (int i = n - 1; i >= 2; i--) { if (a[i] >= a[n]) { result.emplace_back(i - 1); result.emplace_back(i); break; } } } } } else { set<int> segments; for (int i = 1; i < n; i++) { if (a[i] >= a[i + 1]) { if (i > 1) { segments.insert(i - 1); } segments.insert(i); segments.insert(i + 1); for (int j = 1; (int) segments.size() < k - 1; j++) { segments.insert(j); } result.resize(segments.size()); copy(segments.begin(), segments.end(), result.begin()); break; } } } if (!result.empty()) { cout << "TAK" << '\n'; for (int i = 0; i < (int) result.size(); i++) { cout << result[i] << (i == (int) result.size() - 1 ? '\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 | #include <bits/stdc++.h> using namespace std; constexpr int INF = 1'000'000'001; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> min_pref(n + 1, INF), max_suff(n + 2); for (int i = 1; i <= n; i++) { min_pref[i] = min(min_pref[i - 1], a[i]); } for (int i = n; i >= 1; i--) { max_suff[i] = max(max_suff[i + 1], a[i]); } vector<int> result; if (k == 2) { for (int i = 1; i < n; i++) { if (min_pref[i] >= max_suff[i + 1]) { result.emplace_back(i); break; } } } else if (k == 3) { if (a[1] >= a[n]) { result.emplace_back(1); result.emplace_back(n - 1); } else { for (int i = 2; i <= n - 1; i++) { if (a[1] >= a[i]) { result.emplace_back(i - 1); result.emplace_back(i); break; } } if (result.empty()) { for (int i = n - 1; i >= 2; i--) { if (a[i] >= a[n]) { result.emplace_back(i - 1); result.emplace_back(i); break; } } } } } else { set<int> segments; for (int i = 1; i < n; i++) { if (a[i] >= a[i + 1]) { if (i > 1) { segments.insert(i - 1); } segments.insert(i); segments.insert(i + 1); for (int j = 1; (int) segments.size() < k - 1; j++) { segments.insert(j); } result.resize(segments.size()); copy(segments.begin(), segments.end(), result.begin()); break; } } } if (!result.empty()) { cout << "TAK" << '\n'; for (int i = 0; i < (int) result.size(); i++) { cout << result[i] << (i == (int) result.size() - 1 ? '\n' : ' '); } } else { cout << "NIE" << '\n'; } return 0; } |