#include <iostream> using namespace std; typedef int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // data input ll N, K; cin >> N >> K; ll* Tab = new ll[N]; for (ll i = 0; i < N; i++) cin >> Tab[i]; if (K == 2) { ll* MinValues = new ll[N]; ll Min = MinValues[0] = Tab[0]; for (ll i = 1; i < N; i++) { if (Tab[i] < Min) Min = Tab[i]; MinValues[i] = Min; } ll* MaxValues = new ll[N]; ll Max = MaxValues[N - 1] = Tab[N - 1]; for (ll i = N - 2; i >= 0; i--) { if (Max < Tab[i]) Max = Tab[i]; MaxValues[i] = Max; } ll V = -1; for (ll i = 0; i < N - 1; i++) if (MinValues[i] >= MaxValues[i + 1]) { V = i; break; } if (V >= 0) { cout << "TAK\n"; cout << V + 1; } else cout << "NIE"; delete[] MaxValues; delete[] MinValues; } if (K == 3) { ll VMin = 0; ll Min = Tab[0]; for (ll i = 1; i < N; i++) if (Min >= Tab[i]) { VMin = i; break; } ll VMax = N - 1; if (!VMin) { ll Max = Tab[N - 1]; for (ll i = N - 2; i >= 0; i--) if (Tab[i] >= Max) { VMax = i; break; } } if (VMin) { cout << "TAK\n"; cout << VMin << " " << VMin + 1; } else if (VMax < N - 1) { cout << "TAK\n"; cout << VMax - 1 << " " << VMax; } else cout << "NIE"; } if (K >= 4) { ll V = 0; for (ll i = 1; i < N; i++) if (Tab[i - 1] >= Tab[i]) { V = i; break; } if (V) { cout << "TAK\n"; ll VLeft = K - 1; int i = 1; while (VLeft > 3 && i < V - 1) { cout << i << " "; i++; VLeft--; } cout << V - 1 << " " << V << " " << V + 1 << " "; VLeft -= 3; i = V + 2; while (VLeft > 0) { cout << i << " "; i++; VLeft--; } } else cout << "NIE"; } delete[] Tab; 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 135 136 137 138 139 140 141 | #include <iostream> using namespace std; typedef int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // data input ll N, K; cin >> N >> K; ll* Tab = new ll[N]; for (ll i = 0; i < N; i++) cin >> Tab[i]; if (K == 2) { ll* MinValues = new ll[N]; ll Min = MinValues[0] = Tab[0]; for (ll i = 1; i < N; i++) { if (Tab[i] < Min) Min = Tab[i]; MinValues[i] = Min; } ll* MaxValues = new ll[N]; ll Max = MaxValues[N - 1] = Tab[N - 1]; for (ll i = N - 2; i >= 0; i--) { if (Max < Tab[i]) Max = Tab[i]; MaxValues[i] = Max; } ll V = -1; for (ll i = 0; i < N - 1; i++) if (MinValues[i] >= MaxValues[i + 1]) { V = i; break; } if (V >= 0) { cout << "TAK\n"; cout << V + 1; } else cout << "NIE"; delete[] MaxValues; delete[] MinValues; } if (K == 3) { ll VMin = 0; ll Min = Tab[0]; for (ll i = 1; i < N; i++) if (Min >= Tab[i]) { VMin = i; break; } ll VMax = N - 1; if (!VMin) { ll Max = Tab[N - 1]; for (ll i = N - 2; i >= 0; i--) if (Tab[i] >= Max) { VMax = i; break; } } if (VMin) { cout << "TAK\n"; cout << VMin << " " << VMin + 1; } else if (VMax < N - 1) { cout << "TAK\n"; cout << VMax - 1 << " " << VMax; } else cout << "NIE"; } if (K >= 4) { ll V = 0; for (ll i = 1; i < N; i++) if (Tab[i - 1] >= Tab[i]) { V = i; break; } if (V) { cout << "TAK\n"; ll VLeft = K - 1; int i = 1; while (VLeft > 3 && i < V - 1) { cout << i << " "; i++; VLeft--; } cout << V - 1 << " " << V << " " << V + 1 << " "; VLeft -= 3; i = V + 2; while (VLeft > 0) { cout << i << " "; i++; VLeft--; } } else cout << "NIE"; } delete[] Tab; return 0; } |