#include <iostream> #include <vector> #include <algorithm> using namespace std; void printSuccessResult(int index, int rest) { cout << "TAK" << endl; if (rest == -1) { // k=2 cout << index << endl; return; } if (rest == 0) { // k=3 cout << index << " " << index + 1 << endl; return; } // k>3 int restIndex = 1; while (rest > 0 && restIndex < index) { cout << restIndex++ << " "; rest--; } cout << index << " " << index + 1 << " "; restIndex = index + 2; while (rest > 0) { cout << restIndex++ << " "; rest--; } cout << endl; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> values; values.reserve(n); for (int i = 0; i < n; i++) { int v; cin >> v; values.push_back(v); } vector<int> rMax(n, 0), lMin(n, 0); int minValue = values[0]; for (int i = 1; i < n; i++) { lMin[i] = minValue; minValue = min(minValue, values[i]); } int maxValue = values.back(); for (auto i = values.size() - 1; i > 0; i--) { rMax[i] = maxValue; maxValue = max(maxValue, values[i - 1]); } if (k == 2) { int index = 0; for (int i = 1; i < values.size(); i++) { if (lMin[i] >= rMax[i]) { index = i; break; } } if (index) { printSuccessResult(index, -1); return 0; } } if (k == 3) { int index = 0; for (int i = 1; i < values.size(); i++) { if (lMin[i] >= values[i]) { index = i; break; } } if (index) { printSuccessResult(index, k - 3); return 0; } for (int i = values.size() - 1; i >= 0; i--) { if (rMax[i] <= values[i - 1]) { index = i; break; } } if (index) { printSuccessResult(index - 1, k - 3); return 0; } } if (k > 3) { for (int i = 0; i < values.size() - 1; i++) { if (values[i] >= values[i + 1]) { printSuccessResult(i, k - 3); return 0; } } } cout << "NIE" << endl; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; void printSuccessResult(int index, int rest) { cout << "TAK" << endl; if (rest == -1) { // k=2 cout << index << endl; return; } if (rest == 0) { // k=3 cout << index << " " << index + 1 << endl; return; } // k>3 int restIndex = 1; while (rest > 0 && restIndex < index) { cout << restIndex++ << " "; rest--; } cout << index << " " << index + 1 << " "; restIndex = index + 2; while (rest > 0) { cout << restIndex++ << " "; rest--; } cout << endl; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> values; values.reserve(n); for (int i = 0; i < n; i++) { int v; cin >> v; values.push_back(v); } vector<int> rMax(n, 0), lMin(n, 0); int minValue = values[0]; for (int i = 1; i < n; i++) { lMin[i] = minValue; minValue = min(minValue, values[i]); } int maxValue = values.back(); for (auto i = values.size() - 1; i > 0; i--) { rMax[i] = maxValue; maxValue = max(maxValue, values[i - 1]); } if (k == 2) { int index = 0; for (int i = 1; i < values.size(); i++) { if (lMin[i] >= rMax[i]) { index = i; break; } } if (index) { printSuccessResult(index, -1); return 0; } } if (k == 3) { int index = 0; for (int i = 1; i < values.size(); i++) { if (lMin[i] >= values[i]) { index = i; break; } } if (index) { printSuccessResult(index, k - 3); return 0; } for (int i = values.size() - 1; i >= 0; i--) { if (rMax[i] <= values[i - 1]) { index = i; break; } } if (index) { printSuccessResult(index - 1, k - 3); return 0; } } if (k > 3) { for (int i = 0; i < values.size() - 1; i++) { if (values[i] >= values[i + 1]) { printSuccessResult(i, k - 3); return 0; } } } cout << "NIE" << endl; return 0; } |