#include<bits/stdc++.h> using namespace std; constexpr int inf = 1000000000; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> in(n); for (int i = 0; i < n; i++) cin >> in[i]; if (k == 2) { vector<int> min_pref(n + 2, inf); vector<int> max_suf(n + 2, 0); for (int i = 0; i < n; i++) min_pref[i + 1] = min(min_pref[i], in[i]); for (int i = n; i >= 1; i--) max_suf[i] = max(max_suf[i + 1], in[i - 1]); for (int i = 1; i < n; i++) if (min_pref[i] >= max_suf[i + 1]) { cout << "TAK\n" << i << "\n"; return 0; } cout << "NIE\n"; } else if (k == 3) { int mini = *min_element(in.begin(), in.end()); int maxi = *max_element(in.begin(), in.end()); for (int i = 1; i < n; i++) if (in[i] == mini) { int j = min(i, n - 1); cout << "TAK\n" << j << " " << j + 1 << "\n"; return 0; } for (int i = 0; i < n - 1; i++) if (in[i] == maxi) { int j = max(i, 1); cout << "TAK\n" << j << " " << j + 1 << "\n"; return 0; } cout << "NIE\n"; } else { for (int i = 0; i < n - 1; i++) { if (in[i] >= in[i + 1]) { cout << "TAK\n"; int l = min(n - k + 1, max(1, i)); for (int j = 0; j < k - 1; j++) cout << l + j << " "; cout << "\n"; return 0; } } cout << "NIE\n"; } }
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 | #include<bits/stdc++.h> using namespace std; constexpr int inf = 1000000000; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> in(n); for (int i = 0; i < n; i++) cin >> in[i]; if (k == 2) { vector<int> min_pref(n + 2, inf); vector<int> max_suf(n + 2, 0); for (int i = 0; i < n; i++) min_pref[i + 1] = min(min_pref[i], in[i]); for (int i = n; i >= 1; i--) max_suf[i] = max(max_suf[i + 1], in[i - 1]); for (int i = 1; i < n; i++) if (min_pref[i] >= max_suf[i + 1]) { cout << "TAK\n" << i << "\n"; return 0; } cout << "NIE\n"; } else if (k == 3) { int mini = *min_element(in.begin(), in.end()); int maxi = *max_element(in.begin(), in.end()); for (int i = 1; i < n; i++) if (in[i] == mini) { int j = min(i, n - 1); cout << "TAK\n" << j << " " << j + 1 << "\n"; return 0; } for (int i = 0; i < n - 1; i++) if (in[i] == maxi) { int j = max(i, 1); cout << "TAK\n" << j << " " << j + 1 << "\n"; return 0; } cout << "NIE\n"; } else { for (int i = 0; i < n - 1; i++) { if (in[i] >= in[i + 1]) { cout << "TAK\n"; int l = min(n - k + 1, max(1, i)); for (int j = 0; j < k - 1; j++) cout << l + j << " "; cout << "\n"; return 0; } } cout << "NIE\n"; } } |