#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; bool is_increasing(vi& a) { for (int i = 1; i < (int) a.size(); i++) if (a[i-1] >= a[i]) return false; return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vi a(n); for (auto& x : a) cin >> x; if (is_increasing(a)) { cout << "NIE\n"; return 0; } vi max_start(a), min_start(a); // max/min [0,i] vi max_end(a), min_end(a); // max/min [i,n) for (int i = 1; i < n; i++) max_start[i] = max(max_start[i-1], a[i]), min_start[i] = min(min_start[i-1], a[i]); for (int i = n-2; i >= 0; i--) max_end[i] = max(max_end[i+1], a[i]), min_end[i] = min(min_end[i+1], a[i]); if (k == 2) { for (int i = 0; i < n-1; i++) { if (min_start[i] >= max_end[i+1]) { cout << "TAK\n"; cout << i + 1 << '\n'; return 0; } } cout << "NIE\n"; } else if (a[n-1] <= max_start[n-2] || a[0] >= min_end[1]) { int p; if (a[n-1] <= max_start[n-2]) p = max_element(a.begin(), a.end()-1) - a.begin(); else p = min_element(a.begin()+1, a.end()) - a.begin(); cout << "TAK\n"; vector<bool> res(n, false); res[p] = res[p+1] = true; k -= 3; for (int i = 1; k && i < n; i++) if (!res[i]) res[i] = true, k--; for (int i = 1; i < n; i++) if (res[i]) cout << i << ' '; cout << '\n'; } else if (k >= 4) { int s = n - 1; while (a[s] > max_start[s-1]) s--; int p = max_element(a.begin(), a.begin()+s) - a.begin(); // same as in previous case cout << "TAK\n"; vector<bool> res(n, false); res[p] = res[p+1] = res[s+1] = true; k -= 4; for (int i = 1; k && i < n; i++) if (!res[i]) res[i] = true, k--; for (int i = 1; i < n; i++) if (res[i]) cout << i << ' '; 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 | #include <bits/stdc++.h> using namespace std; typedef vector<int> vi; bool is_increasing(vi& a) { for (int i = 1; i < (int) a.size(); i++) if (a[i-1] >= a[i]) return false; return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vi a(n); for (auto& x : a) cin >> x; if (is_increasing(a)) { cout << "NIE\n"; return 0; } vi max_start(a), min_start(a); // max/min [0,i] vi max_end(a), min_end(a); // max/min [i,n) for (int i = 1; i < n; i++) max_start[i] = max(max_start[i-1], a[i]), min_start[i] = min(min_start[i-1], a[i]); for (int i = n-2; i >= 0; i--) max_end[i] = max(max_end[i+1], a[i]), min_end[i] = min(min_end[i+1], a[i]); if (k == 2) { for (int i = 0; i < n-1; i++) { if (min_start[i] >= max_end[i+1]) { cout << "TAK\n"; cout << i + 1 << '\n'; return 0; } } cout << "NIE\n"; } else if (a[n-1] <= max_start[n-2] || a[0] >= min_end[1]) { int p; if (a[n-1] <= max_start[n-2]) p = max_element(a.begin(), a.end()-1) - a.begin(); else p = min_element(a.begin()+1, a.end()) - a.begin(); cout << "TAK\n"; vector<bool> res(n, false); res[p] = res[p+1] = true; k -= 3; for (int i = 1; k && i < n; i++) if (!res[i]) res[i] = true, k--; for (int i = 1; i < n; i++) if (res[i]) cout << i << ' '; cout << '\n'; } else if (k >= 4) { int s = n - 1; while (a[s] > max_start[s-1]) s--; int p = max_element(a.begin(), a.begin()+s) - a.begin(); // same as in previous case cout << "TAK\n"; vector<bool> res(n, false); res[p] = res[p+1] = res[s+1] = true; k -= 4; for (int i = 1; k && i < n; i++) if (!res[i]) res[i] = true, k--; for (int i = 1; i < n; i++) if (res[i]) cout << i << ' '; cout << '\n'; } else cout << "NIE\n"; return 0; } |