#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll inf = 1e18 + 7; ll n , k , ans = 0 , q , start_k; vector<ll>res , vec(500005); vector<bool>used(500005); void add(ll nom) { if (nom < 1 || nom > n)return; if (nom == 1) { if (used[1])return; used[1] = 1; res.push_back(1); k--; } else if (nom == n) { if (used[n - 1])return; used[n - 1] = 1; res.push_back(n - 1); k--; } else { if (!used[nom - 1]) { used[nom - 1] = 1; res.push_back(nom - 1); k--; } if (!used[nom]) { used[nom] = 1; res.push_back(nom); k--; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; // cout << "n = " << n << " k = " << k << endl; for (int i = 1; i <= n; i++) { cin >> vec[i]; used[i] = 0; } vector<ll>min_pref(n + 5 , inf) , max_suf(n + 5 , -inf); for (int i = 1; i <= n; i++) { min_pref[i] = min(min_pref[i - 1] , vec[i]); } min_pref[0] = -inf; for (int i = n; i; i--) { max_suf[i] = max(max_suf[i + 1] , vec[i]); } max_suf[n + 1] = inf; // cout << real_res << endl; if (k == 2) { bool can = 0; for (int i = 1; i < n; i++) { if (min_pref[i] >= max_suf[i + 1]) { res.push_back(i); can = 1; break; } } if (!can) { cout << "NIE"; return 0; } cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } else if (k == 3) { k--; bool can = 0; for (int i = 1; i <= n; i++) { if (!(min_pref[i - 1] < vec[i] && vec[i] < max_suf[i + 1])) { add(i); can = 1; break; } } if (!can) { cout << "NIE"; return 0; } for (int i = 1; i <= n; i++) { if (k == 0)break; add(i); } sort(res.begin() , res.end()); cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } else if (k == 4) { k--; bool can = 0; for (int i = 2; i <= n - 2; i++) { ll ch1 = min_pref[i - 1] , ch2 = vec[i] , ch3 = vec[i + 1] , ch4 = max_suf[i + 2]; if (!(ch1 < ch2 && ch2 < ch3 && ch3 < ch4)) { add(i); add(i + 1); can = 1; break; } } if (!can) { cout << "NIE"; return 0; } for (int i = 1; i <= n; i++) { if (k == 0)break; add(i); } sort(res.begin() , res.end()); cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } else { k--; ll cur_max = vec[1] , nom = 1; bool can = 0; for (int i = 2; i <= n; i++) { if (vec[i] <= cur_max) { add(i); add(nom); can = 1; break; } if (cur_max < vec[i]) { cur_max = vec[i]; nom = i; } } if (!can) { cout << "NIE"; return 0; } for (int i = 1; i <= n; i++) { if (k == 0)break; add(i); } sort(res.begin() , res.end()); cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } } //Misha_Yuzvik
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 | #include <bits/stdc++.h> typedef long long ll; using namespace std; const ll inf = 1e18 + 7; ll n , k , ans = 0 , q , start_k; vector<ll>res , vec(500005); vector<bool>used(500005); void add(ll nom) { if (nom < 1 || nom > n)return; if (nom == 1) { if (used[1])return; used[1] = 1; res.push_back(1); k--; } else if (nom == n) { if (used[n - 1])return; used[n - 1] = 1; res.push_back(n - 1); k--; } else { if (!used[nom - 1]) { used[nom - 1] = 1; res.push_back(nom - 1); k--; } if (!used[nom]) { used[nom] = 1; res.push_back(nom); k--; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; // cout << "n = " << n << " k = " << k << endl; for (int i = 1; i <= n; i++) { cin >> vec[i]; used[i] = 0; } vector<ll>min_pref(n + 5 , inf) , max_suf(n + 5 , -inf); for (int i = 1; i <= n; i++) { min_pref[i] = min(min_pref[i - 1] , vec[i]); } min_pref[0] = -inf; for (int i = n; i; i--) { max_suf[i] = max(max_suf[i + 1] , vec[i]); } max_suf[n + 1] = inf; // cout << real_res << endl; if (k == 2) { bool can = 0; for (int i = 1; i < n; i++) { if (min_pref[i] >= max_suf[i + 1]) { res.push_back(i); can = 1; break; } } if (!can) { cout << "NIE"; return 0; } cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } else if (k == 3) { k--; bool can = 0; for (int i = 1; i <= n; i++) { if (!(min_pref[i - 1] < vec[i] && vec[i] < max_suf[i + 1])) { add(i); can = 1; break; } } if (!can) { cout << "NIE"; return 0; } for (int i = 1; i <= n; i++) { if (k == 0)break; add(i); } sort(res.begin() , res.end()); cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } else if (k == 4) { k--; bool can = 0; for (int i = 2; i <= n - 2; i++) { ll ch1 = min_pref[i - 1] , ch2 = vec[i] , ch3 = vec[i + 1] , ch4 = max_suf[i + 2]; if (!(ch1 < ch2 && ch2 < ch3 && ch3 < ch4)) { add(i); add(i + 1); can = 1; break; } } if (!can) { cout << "NIE"; return 0; } for (int i = 1; i <= n; i++) { if (k == 0)break; add(i); } sort(res.begin() , res.end()); cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } else { k--; ll cur_max = vec[1] , nom = 1; bool can = 0; for (int i = 2; i <= n; i++) { if (vec[i] <= cur_max) { add(i); add(nom); can = 1; break; } if (cur_max < vec[i]) { cur_max = vec[i]; nom = i; } } if (!can) { cout << "NIE"; return 0; } for (int i = 1; i <= n; i++) { if (k == 0)break; add(i); } sort(res.begin() , res.end()); cout << "TAK" << endl; for (auto v : res)cout << v << ' '; } } //Misha_Yuzvik |