#include <bits/stdc++.h> using namespace std; int length, groups; int* values; void compute2() { int* maxs = new int[length]; int* mins = new int[length]; int min = 1000000001; for (int i = 0; i < length; ++i) { if (values[i] < min) { min = values[i]; } mins[i] = min; } int max = 0; for (int i = length - 1; i >= 0; i--) { if (values[i] > max) { max = values[i]; } maxs[i] = max; } for (int i = 0; i < length - 1; ++i) { if (mins[i] >= maxs[i+1]) { cout << "TAK" << endl; cout << i + 1 << endl; return; } } cout << "NIE" << endl; } void compute3() { int min = 1000000001; int minIndex = -1; for (int i = 0; i <length; ++i) { if (values[i] <= min) { minIndex = i; min = values[i]; } } if (minIndex > 0) { cout << "TAK" << endl; if (minIndex == length-1) { cout << minIndex-1 << " " << minIndex << endl; } else { cout << minIndex << " " << minIndex+1 << endl; } return; } int max = 0; int maxIndex = -1; for (int i = length-1; i >= 0; i--) { if (values[i] >= max) { maxIndex = i; max = values[i]; } } if (maxIndex < length - 1) { cout << "TAK" << endl; if (maxIndex == 0) { cout << 1 << " " << 2 << endl; } else { cout << maxIndex << " " << maxIndex+1 << endl; } return; } cout << "NIE" << endl; } void compute4() { int index = -1; for (int i = 0; i <length-1; ++i) { if (values[i] >= values[i+1]) { index = i; break; } } if (index < 0) { cout << "NIE" << endl; return; } else { cout << "TAK" << endl; } groups -= 2; int rest; if (index < length-2) { rest = 2; } else { rest = 1; } int i = 1; while (groups > rest && i < index + 1) { cout << i++ << " "; groups--; } if (i < index) { cout << index << " "; groups--; } cout << index+1; if (index < length-2) { cout << " " << index+2; } i = index+3; while (groups > 1) { cout << " " << i++; groups--; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> length >> groups; values = new int[length]; for (int i = 0; i < length; ++i) { cin >> values[i]; } if (groups == 2) { compute2(); } else if (groups == 3) { compute3(); } else { compute4(); } 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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #include <bits/stdc++.h> using namespace std; int length, groups; int* values; void compute2() { int* maxs = new int[length]; int* mins = new int[length]; int min = 1000000001; for (int i = 0; i < length; ++i) { if (values[i] < min) { min = values[i]; } mins[i] = min; } int max = 0; for (int i = length - 1; i >= 0; i--) { if (values[i] > max) { max = values[i]; } maxs[i] = max; } for (int i = 0; i < length - 1; ++i) { if (mins[i] >= maxs[i+1]) { cout << "TAK" << endl; cout << i + 1 << endl; return; } } cout << "NIE" << endl; } void compute3() { int min = 1000000001; int minIndex = -1; for (int i = 0; i <length; ++i) { if (values[i] <= min) { minIndex = i; min = values[i]; } } if (minIndex > 0) { cout << "TAK" << endl; if (minIndex == length-1) { cout << minIndex-1 << " " << minIndex << endl; } else { cout << minIndex << " " << minIndex+1 << endl; } return; } int max = 0; int maxIndex = -1; for (int i = length-1; i >= 0; i--) { if (values[i] >= max) { maxIndex = i; max = values[i]; } } if (maxIndex < length - 1) { cout << "TAK" << endl; if (maxIndex == 0) { cout << 1 << " " << 2 << endl; } else { cout << maxIndex << " " << maxIndex+1 << endl; } return; } cout << "NIE" << endl; } void compute4() { int index = -1; for (int i = 0; i <length-1; ++i) { if (values[i] >= values[i+1]) { index = i; break; } } if (index < 0) { cout << "NIE" << endl; return; } else { cout << "TAK" << endl; } groups -= 2; int rest; if (index < length-2) { rest = 2; } else { rest = 1; } int i = 1; while (groups > rest && i < index + 1) { cout << i++ << " "; groups--; } if (i < index) { cout << index << " "; groups--; } cout << index+1; if (index < length-2) { cout << " " << index+2; } i = index+3; while (groups > 1) { cout << " " << i++; groups--; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> length >> groups; values = new int[length]; for (int i = 0; i < length; ++i) { cin >> values[i]; } if (groups == 2) { compute2(); } else if (groups == 3) { compute3(); } else { compute4(); } return 0; } |