#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; int* nums = new int[n]; vector<int> cuts; int firstNotIncreasing = -1; int last = 0; for (int i = 0; i < n; i++) { cin >> nums[i]; if (last >= nums[i] && firstNotIncreasing == -1) { firstNotIncreasing = i; } last = nums[i]; } if (firstNotIncreasing == -1) { cout << "NIE"; return 0; } bool* used = new bool[n] {0}; if (k >= 4) { int i = 0; if (firstNotIncreasing < n - 1) { cuts.push_back(firstNotIncreasing + 1); used[firstNotIncreasing + 1] = 1; } if (firstNotIncreasing > 0) { cuts.push_back(firstNotIncreasing); used[firstNotIncreasing] = 1; } if (firstNotIncreasing - 1 > 0) { cuts.push_back(firstNotIncreasing - 1); used[firstNotIncreasing - 1] = 1; } while (cuts.size() != k) { i++; if (used[i]) continue; cuts.push_back(i); } } if (k >= 3 && cuts.size() == 0) { int max = 0; int min = 0; for (int i = 1; i < n; i++) { if (nums[i] > nums[max]) max = i; if (nums[i] <= nums[min]) min = i; } if (min != 0) { cuts.push_back(min); if (min < n - 1) cuts.push_back(min + 1); else if (cuts.size() == 1) { if (cuts[0] != 1) cuts.push_back(1); else cuts.push_back(2); } } if (max < n - 1&&cuts.size()==0) { cuts.push_back(max + 1); if (max > 0) cuts.push_back(max); else if (cuts.size() == 1) { if (cuts[0] != 1) cuts.push_back(1); else cuts.push_back(2); } } }if (k >= 2 && cuts.size() == 0) { int lastIncreasingPos = -1; int* min = new int[n] {0}; min[0] = nums[0]; for (int i = 1; i < n; i++) { min[i] = ((min[i - 1] < nums[i]) ? min[i - 1] : nums[i]); } int max = nums[n - 1]; for (int i = n - 2; i >= 0; i--) { if (min[i] >= max) { cuts.push_back(i + 1); break; } if (cuts.size() > 0) break; if (nums[i] > max) max = nums[i]; } } if (cuts.size() == 0) { cout << "NIE"; return 0; } sort(cuts.begin(), cuts.end()); cout << "TAK\n"; for (int i = 0; i < cuts.size(); i++) { cout << cuts[i] << " "; } }
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; int* nums = new int[n]; vector<int> cuts; int firstNotIncreasing = -1; int last = 0; for (int i = 0; i < n; i++) { cin >> nums[i]; if (last >= nums[i] && firstNotIncreasing == -1) { firstNotIncreasing = i; } last = nums[i]; } if (firstNotIncreasing == -1) { cout << "NIE"; return 0; } bool* used = new bool[n] {0}; if (k >= 4) { int i = 0; if (firstNotIncreasing < n - 1) { cuts.push_back(firstNotIncreasing + 1); used[firstNotIncreasing + 1] = 1; } if (firstNotIncreasing > 0) { cuts.push_back(firstNotIncreasing); used[firstNotIncreasing] = 1; } if (firstNotIncreasing - 1 > 0) { cuts.push_back(firstNotIncreasing - 1); used[firstNotIncreasing - 1] = 1; } while (cuts.size() != k) { i++; if (used[i]) continue; cuts.push_back(i); } } if (k >= 3 && cuts.size() == 0) { int max = 0; int min = 0; for (int i = 1; i < n; i++) { if (nums[i] > nums[max]) max = i; if (nums[i] <= nums[min]) min = i; } if (min != 0) { cuts.push_back(min); if (min < n - 1) cuts.push_back(min + 1); else if (cuts.size() == 1) { if (cuts[0] != 1) cuts.push_back(1); else cuts.push_back(2); } } if (max < n - 1&&cuts.size()==0) { cuts.push_back(max + 1); if (max > 0) cuts.push_back(max); else if (cuts.size() == 1) { if (cuts[0] != 1) cuts.push_back(1); else cuts.push_back(2); } } }if (k >= 2 && cuts.size() == 0) { int lastIncreasingPos = -1; int* min = new int[n] {0}; min[0] = nums[0]; for (int i = 1; i < n; i++) { min[i] = ((min[i - 1] < nums[i]) ? min[i - 1] : nums[i]); } int max = nums[n - 1]; for (int i = n - 2; i >= 0; i--) { if (min[i] >= max) { cuts.push_back(i + 1); break; } if (cuts.size() > 0) break; if (nums[i] > max) max = nums[i]; } } if (cuts.size() == 0) { cout << "NIE"; return 0; } sort(cuts.begin(), cuts.end()); cout << "TAK\n"; for (int i = 0; i < cuts.size(); i++) { cout << cuts[i] << " "; } } |