#include <bits/stdc++.h> #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define watch(x) cout << (#x) << " : " << x << '\n' using namespace std; void solve() { int n, k; cin >> n >> k; vector <int> a(n); for (auto& x : a) cin >> x; vector <int> pref(n), suf(n); pref[0] = a[0]; suf[n - 1] = a[n - 1]; for (int i = 1; i < n; i++) pref[i] = min(pref[i - 1], a[i]); for (int i = n - 2; i >= 0; i--) suf[i] = max(a[i], suf[i + 1]); if (k == 2) { for (int i = 1; i < n; i++) { if (pref[i - 1] >= suf[i]) { cout << "TAK\n" << i << '\n'; return; } } cout << "NIE\n"; return; } if (k == 3) { for (int i = 1; i + 1 < n; i++) { if (pref[i - 1] >= a[i] || a[i] >= suf[i + 1]) { cout << "TAK\n" << i << ' ' << i + 1 << '\n'; return; } } cout << "NIE\n"; return; } for (int i = 1; i < n; i++) { if (a[i - 1] >= a[i]) { cout << "TAK\n"; vector <int> ans; ans.push_back(i); ans.push_back(i + 1); k -= 2; if (i - 1) ans.push_back(i - 1), k--; if (i + 1 != n) k--; int lst_un = 1; while (k > 0) { if (lst_un == i || lst_un == i + 1 || lst_un == i - 1) { lst_un++; continue; } ans.push_back(lst_un++); k--; } sort(all(ans)); if (ans.back() == n) ans.pop_back(); for (auto c : ans) cout << c << ' '; cout << '\n'; return; } } cout << "NIE\n"; } int main() { boost; solve(); 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 | #include <bits/stdc++.h> #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define watch(x) cout << (#x) << " : " << x << '\n' using namespace std; void solve() { int n, k; cin >> n >> k; vector <int> a(n); for (auto& x : a) cin >> x; vector <int> pref(n), suf(n); pref[0] = a[0]; suf[n - 1] = a[n - 1]; for (int i = 1; i < n; i++) pref[i] = min(pref[i - 1], a[i]); for (int i = n - 2; i >= 0; i--) suf[i] = max(a[i], suf[i + 1]); if (k == 2) { for (int i = 1; i < n; i++) { if (pref[i - 1] >= suf[i]) { cout << "TAK\n" << i << '\n'; return; } } cout << "NIE\n"; return; } if (k == 3) { for (int i = 1; i + 1 < n; i++) { if (pref[i - 1] >= a[i] || a[i] >= suf[i + 1]) { cout << "TAK\n" << i << ' ' << i + 1 << '\n'; return; } } cout << "NIE\n"; return; } for (int i = 1; i < n; i++) { if (a[i - 1] >= a[i]) { cout << "TAK\n"; vector <int> ans; ans.push_back(i); ans.push_back(i + 1); k -= 2; if (i - 1) ans.push_back(i - 1), k--; if (i + 1 != n) k--; int lst_un = 1; while (k > 0) { if (lst_un == i || lst_un == i + 1 || lst_un == i - 1) { lst_un++; continue; } ans.push_back(lst_un++); k--; } sort(all(ans)); if (ans.back() == n) ans.pop_back(); for (auto c : ans) cout << c << ' '; cout << '\n'; return; } } cout << "NIE\n"; } int main() { boost; solve(); return 0; } |