#include <bits/stdc++.h> using namespace std; int32_t n, k, a[500000]; int main() { scanf("%" SCNd32 "%" SCNd32, &n, &k); for (int32_t i = 0; i < n; ++i) scanf("%" SCNd32, a + i); if (k > 3) { for (int32_t i = 1; i < n; ++i) if (a[i] <= a[i - 1]) { printf("TAK\n"); int32_t px = 1; if (i == n - 1) { while (k != 3) { printf("%" PRId32 " ", px); ++px; --k; } printf("%" PRId32 " %" PRId32 "\n", n - 2, n - 1); return 0; } if (i == 1) { printf("1 2"); k -= 3; } else { while (k != 4 && px < i - 1) { printf("%" PRId32 " ", px); ++px; --k; } printf("%" PRId32 " %" PRId32 " %" PRId32, i - 1, i, i + 1); k -= 4; } px = i + 2; while (k != 0) { printf(" %" PRId32, px); ++px; --k; } printf("\n"); return 0; } printf("NIE\n"); } else if (k == 3) { if (*a >= a[n - 1]) { printf("TAK\n1 %" PRId32 "\n", n - 1); return 0; } int32_t p = *a; for (int32_t i = 1; i < n; ++i) { if (a[i] <= p) { printf("TAK\n%" PRId32 " %" PRId32 "\n", i, i + 1); return 0; } if (a[i] < p) p = a[i]; } p = a[n - 1]; for (int32_t i = n - 2; i >= 0; --i) { if (a[i] >= p) { printf("TAK\n%" PRId32 " %" PRId32 "\n", i, i + 1); return 0; } if (a[i] > p) p = a[i]; } printf("NIE\n"); } else { int32_t maxi[n]; for (int32_t i = n - 1; i >= 0; --i) maxi[i] = i == n - 1 ? a[n - 1] : max(a[i], maxi[i + 1]); int32_t p = INT32_MAX; for (int32_t i = 0; i <= n - 2; ++i) { if (a[i] < p) p = a[i]; if (p >= maxi[i + 1]) { printf("TAK\n%" PRId32 "\n", i + 1); return 0; } } printf("NIE\n"); } }
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 | #include <bits/stdc++.h> using namespace std; int32_t n, k, a[500000]; int main() { scanf("%" SCNd32 "%" SCNd32, &n, &k); for (int32_t i = 0; i < n; ++i) scanf("%" SCNd32, a + i); if (k > 3) { for (int32_t i = 1; i < n; ++i) if (a[i] <= a[i - 1]) { printf("TAK\n"); int32_t px = 1; if (i == n - 1) { while (k != 3) { printf("%" PRId32 " ", px); ++px; --k; } printf("%" PRId32 " %" PRId32 "\n", n - 2, n - 1); return 0; } if (i == 1) { printf("1 2"); k -= 3; } else { while (k != 4 && px < i - 1) { printf("%" PRId32 " ", px); ++px; --k; } printf("%" PRId32 " %" PRId32 " %" PRId32, i - 1, i, i + 1); k -= 4; } px = i + 2; while (k != 0) { printf(" %" PRId32, px); ++px; --k; } printf("\n"); return 0; } printf("NIE\n"); } else if (k == 3) { if (*a >= a[n - 1]) { printf("TAK\n1 %" PRId32 "\n", n - 1); return 0; } int32_t p = *a; for (int32_t i = 1; i < n; ++i) { if (a[i] <= p) { printf("TAK\n%" PRId32 " %" PRId32 "\n", i, i + 1); return 0; } if (a[i] < p) p = a[i]; } p = a[n - 1]; for (int32_t i = n - 2; i >= 0; --i) { if (a[i] >= p) { printf("TAK\n%" PRId32 " %" PRId32 "\n", i, i + 1); return 0; } if (a[i] > p) p = a[i]; } printf("NIE\n"); } else { int32_t maxi[n]; for (int32_t i = n - 1; i >= 0; --i) maxi[i] = i == n - 1 ? a[n - 1] : max(a[i], maxi[i + 1]); int32_t p = INT32_MAX; for (int32_t i = 0; i <= n - 2; ++i) { if (a[i] < p) p = a[i]; if (p >= maxi[i + 1]) { printf("TAK\n%" PRId32 "\n", i + 1); return 0; } } printf("NIE\n"); } } |