#include <iostream> using namespace std; int main() { int numsQuantity, groupsQuantity; int negativeDifferencesQuantity = 0; int previousLocalMax = -1; int localMax = -1; bool isLocalMaxEqualPreviousLocalMax = false; cin >> numsQuantity >> groupsQuantity; int* nums = new int[numsQuantity]; int* differences = new int[numsQuantity]; for (int i = 0; i < numsQuantity; i++) { cin >> nums[i]; } differences[0] = nums[0]; for (int i = 1; i < numsQuantity; i++) { differences[i] = nums[i] - nums[i - 1]; if (nums[i] > localMax) { localMax = nums[i]; } /*if (previousLocalMax == localMax) { isLocalMaxEqualPreviousLocalMax = true; break; }*/ if (differences[i] < 0) { negativeDifferencesQuantity++; previousLocalMax = localMax; } } /*if (isLocalMaxEqualPreviousLocalMax) { cout << "NIE" << endl; return 0; }*/ if (negativeDifferencesQuantity + 1 >= groupsQuantity) { cout << "TAK\n"; for (int i = 0; i < numsQuantity; i++) { if (differences[i] < 0) { cout << i + 1 << " "; } } cout << "\n"; } else { cout << "NIE" << endl; return 0; } 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 | #include <iostream> using namespace std; int main() { int numsQuantity, groupsQuantity; int negativeDifferencesQuantity = 0; int previousLocalMax = -1; int localMax = -1; bool isLocalMaxEqualPreviousLocalMax = false; cin >> numsQuantity >> groupsQuantity; int* nums = new int[numsQuantity]; int* differences = new int[numsQuantity]; for (int i = 0; i < numsQuantity; i++) { cin >> nums[i]; } differences[0] = nums[0]; for (int i = 1; i < numsQuantity; i++) { differences[i] = nums[i] - nums[i - 1]; if (nums[i] > localMax) { localMax = nums[i]; } /*if (previousLocalMax == localMax) { isLocalMaxEqualPreviousLocalMax = true; break; }*/ if (differences[i] < 0) { negativeDifferencesQuantity++; previousLocalMax = localMax; } } /*if (isLocalMaxEqualPreviousLocalMax) { cout << "NIE" << endl; return 0; }*/ if (negativeDifferencesQuantity + 1 >= groupsQuantity) { cout << "TAK\n"; for (int i = 0; i < numsQuantity; i++) { if (differences[i] < 0) { cout << i + 1 << " "; } } cout << "\n"; } else { cout << "NIE" << endl; return 0; } return 0; } |