#include <bits/stdc++.h> using namespace std; #ifdef D #define DEBUG(x) \ do { \ x \ cout.flush(); \ } while (0) #else #define DEBUG(x) #endif using ll = long long; const int NMAX = 5e5 + 7, inf = 1e9 + 7; int n, k; int t[NMAX], prefmin[NMAX], sufmax[NMAX], sufmin[NMAX]; set<int> cuts; void finish() { for (int i = 1; cuts.size() < k - 1; ++i) { cuts.insert(i); } for (int c : cuts) { cout << c << " "; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; prefmin[0] = inf; sufmin[n + 1] = inf; for (int i = 1; i <= n; ++i) { cin >> t[i]; prefmin[i] = min(prefmin[i - 1], t[i]); } for (int i = n; i > 0; --i) { sufmax[i] = max(sufmax[i + 1], t[i]); sufmin[i] = min(sufmin[i + 1], t[i]); } if (k == 2) { for (int i = 1; i < n; ++i) { if (prefmin[i] >= sufmax[i + 1]) { cout << "TAK\n" << i; return 0; } } cout << "NIE\n"; } else if (k == 3) { for (int i = 1; i < n; ++i) { if (t[i] >= sufmax[i + 1]) { cout << "TAK\n"; if (i == 1) { cout << "1 2"; } else { cout << i - 1 << " " << i; } return 0; } } for (int i = 2; i <= n; ++i) { if (t[i] <= prefmin[i - 1]) { cout << "TAK\n"; if (i == n) { cout << n - 2 << " " << n - 1; } else { cout << i - 1 << " " << i; } return 0; } } cout << "NIE\n"; } else { for (int i = 1; i < n; ++i) { if (t[i] >= sufmin[i + 1]) { cout << "TAK\n"; if (i == 1) { cuts.insert(1); } else { cuts.insert(i - 1); cuts.insert(i); } for (int j = i + 1; j <= n; ++j) { if (t[i] >= t[j]) { if (j == n) { cuts.insert(n - 1); } else { cuts.insert(j - 1); cuts.insert(j); } } } finish(); 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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | #include <bits/stdc++.h> using namespace std; #ifdef D #define DEBUG(x) \ do { \ x \ cout.flush(); \ } while (0) #else #define DEBUG(x) #endif using ll = long long; const int NMAX = 5e5 + 7, inf = 1e9 + 7; int n, k; int t[NMAX], prefmin[NMAX], sufmax[NMAX], sufmin[NMAX]; set<int> cuts; void finish() { for (int i = 1; cuts.size() < k - 1; ++i) { cuts.insert(i); } for (int c : cuts) { cout << c << " "; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; prefmin[0] = inf; sufmin[n + 1] = inf; for (int i = 1; i <= n; ++i) { cin >> t[i]; prefmin[i] = min(prefmin[i - 1], t[i]); } for (int i = n; i > 0; --i) { sufmax[i] = max(sufmax[i + 1], t[i]); sufmin[i] = min(sufmin[i + 1], t[i]); } if (k == 2) { for (int i = 1; i < n; ++i) { if (prefmin[i] >= sufmax[i + 1]) { cout << "TAK\n" << i; return 0; } } cout << "NIE\n"; } else if (k == 3) { for (int i = 1; i < n; ++i) { if (t[i] >= sufmax[i + 1]) { cout << "TAK\n"; if (i == 1) { cout << "1 2"; } else { cout << i - 1 << " " << i; } return 0; } } for (int i = 2; i <= n; ++i) { if (t[i] <= prefmin[i - 1]) { cout << "TAK\n"; if (i == n) { cout << n - 2 << " " << n - 1; } else { cout << i - 1 << " " << i; } return 0; } } cout << "NIE\n"; } else { for (int i = 1; i < n; ++i) { if (t[i] >= sufmin[i + 1]) { cout << "TAK\n"; if (i == 1) { cuts.insert(1); } else { cuts.insert(i - 1); cuts.insert(i); } for (int j = i + 1; j <= n; ++j) { if (t[i] >= t[j]) { if (j == n) { cuts.insert(n - 1); } else { cuts.insert(j - 1); cuts.insert(j); } } } finish(); return 0; } } cout << "NIE\n"; } return 0; } |