#include <iostream> using namespace std; int max(int a, int b) { return a > b ? a : b; } void equals_two(int incomes[], int n) { int minimum[n+1], maximum[n+1]; minimum[1] = incomes[1]; for (int i = 2; i <= n; i++) minimum[i] = incomes[i] < minimum[i-1] ? incomes[i] : minimum[i-1]; maximum[n] = incomes[n]; for (int i = n-1; i >= 1; i--) maximum[i] = incomes[i] > maximum[i+1] ? incomes[i] : maximum[i+1]; bool possible = false; int v; for (int i = 1; i < n; i++) { if (minimum[i] >= maximum[i+1]) { possible = true; v = i; break; } } if (possible) cout << "TAK\n" << v << "\n"; else cout << "NIE\n"; } void equals_three(int incomes[], int n) { int maximum = 1, minimum = n; for (int i = n-1; i >= 1; i--) if (incomes[i] < incomes[minimum]) minimum = i; for (int i = 2; i <= n; i++) if (incomes[i] > incomes[maximum]) maximum = i; if (minimum != 1) { cout << "TAK\n"; if (minimum == n) cout << n-2 << " " << n-1 << "\n"; else cout << minimum-1 << " " << minimum << "\n"; } else if (maximum != n) { cout << "TAK\n"; if (maximum == 1) cout << 1 << " " << 2 << "\n"; else cout << maximum-1 << " " << maximum << "\n"; } else { cout << "NIE\n"; } } void bigger_then_three(int incomes[], int n, int k) { int v; bool possible = false; for (int i = 1; i < n; i++) { if (incomes[i+1] <= incomes[i]) { possible = true; v = i; break; } } if (possible) { cout << "TAK\n"; int start = max(1, v-k+3); for (int i = 0; i < k-1; i++) cout << start+i << " "; cout << "\n"; } else { cout << "NIE\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int incomes[n+1]; for (int i = 1; i <= n; i++) cin >> incomes[i]; if (k == 2) { equals_two(incomes, n); } else if (k == 3) { equals_three(incomes, n); } else { bigger_then_three(incomes, n, k); } 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 | #include <iostream> using namespace std; int max(int a, int b) { return a > b ? a : b; } void equals_two(int incomes[], int n) { int minimum[n+1], maximum[n+1]; minimum[1] = incomes[1]; for (int i = 2; i <= n; i++) minimum[i] = incomes[i] < minimum[i-1] ? incomes[i] : minimum[i-1]; maximum[n] = incomes[n]; for (int i = n-1; i >= 1; i--) maximum[i] = incomes[i] > maximum[i+1] ? incomes[i] : maximum[i+1]; bool possible = false; int v; for (int i = 1; i < n; i++) { if (minimum[i] >= maximum[i+1]) { possible = true; v = i; break; } } if (possible) cout << "TAK\n" << v << "\n"; else cout << "NIE\n"; } void equals_three(int incomes[], int n) { int maximum = 1, minimum = n; for (int i = n-1; i >= 1; i--) if (incomes[i] < incomes[minimum]) minimum = i; for (int i = 2; i <= n; i++) if (incomes[i] > incomes[maximum]) maximum = i; if (minimum != 1) { cout << "TAK\n"; if (minimum == n) cout << n-2 << " " << n-1 << "\n"; else cout << minimum-1 << " " << minimum << "\n"; } else if (maximum != n) { cout << "TAK\n"; if (maximum == 1) cout << 1 << " " << 2 << "\n"; else cout << maximum-1 << " " << maximum << "\n"; } else { cout << "NIE\n"; } } void bigger_then_three(int incomes[], int n, int k) { int v; bool possible = false; for (int i = 1; i < n; i++) { if (incomes[i+1] <= incomes[i]) { possible = true; v = i; break; } } if (possible) { cout << "TAK\n"; int start = max(1, v-k+3); for (int i = 0; i < k-1; i++) cout << start+i << " "; cout << "\n"; } else { cout << "NIE\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int incomes[n+1]; for (int i = 1; i <= n; i++) cin >> incomes[i]; if (k == 2) { equals_two(incomes, n); } else if (k == 3) { equals_three(incomes, n); } else { bigger_then_three(incomes, n, k); } return 0; } |