#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
const int maxN = 5e5 + 10;
const int inf = 1e9 + 7;
int N, K;
int t[maxN];
void nope() {
puts("NIE");
exit(0);
}
void k2() {
vector<int> maxes(N, -inf);
maxes.back() = t[N - 1];
for (int i = N - 2; i >= 0; --i)
maxes[i] = max(t[i], maxes[i + 1]);
int mins = t[0];
for (int i = 1; i < N; ++i) {
if (mins >= maxes[i]) {
puts("TAK");
printf("%d\n", i);
exit(0);
}
mins = min(mins, t[i]);
}
nope();
}
void k3() {
int lastmin = 0, firstmax = 0;
for (int i = 1; i < N; ++i) {
if (t[i] <= t[lastmin])
lastmin = i;
if (t[i] > t[firstmax])
firstmax = i;
}
if (lastmin == 0 && firstmax == N - 1)
nope();
puts("TAK");
if (lastmin > 0)
printf("%d %d\n", lastmin, lastmin + 1);
else
printf("%d %d\n", firstmax, firstmax + 1);
exit(0);
}
void k() {
int i0 = 1;
while (i0 < N && t[i0 - 1] < t[i0])
i0++;
if (i0 == N)
nope();
vector<int> result;
int left = K - 4;
if (i0 == 1 || i0 == N - 1)
left++;
for (int i = 1; i < N; ++i) {
if (i0 - 1 <= i && i <= i0 + 1) {
result.push_back(i);
continue;
}
if (left) {
result.push_back(i);
left--;
}
}
puts("TAK");
for (int a : result)
printf("%d ", a);
puts("");
exit(0);
}
int main() {
scanf("%d%d", &N, &K);
for (int i = 0; i < N; ++i)
scanf("%d", t + i);
if (K == 2)
k2();
if (K == 3)
k3();
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 | #include <algorithm> #include <cstdio> #include <vector> using namespace std; const int maxN = 5e5 + 10; const int inf = 1e9 + 7; int N, K; int t[maxN]; void nope() { puts("NIE"); exit(0); } void k2() { vector<int> maxes(N, -inf); maxes.back() = t[N - 1]; for (int i = N - 2; i >= 0; --i) maxes[i] = max(t[i], maxes[i + 1]); int mins = t[0]; for (int i = 1; i < N; ++i) { if (mins >= maxes[i]) { puts("TAK"); printf("%d\n", i); exit(0); } mins = min(mins, t[i]); } nope(); } void k3() { int lastmin = 0, firstmax = 0; for (int i = 1; i < N; ++i) { if (t[i] <= t[lastmin]) lastmin = i; if (t[i] > t[firstmax]) firstmax = i; } if (lastmin == 0 && firstmax == N - 1) nope(); puts("TAK"); if (lastmin > 0) printf("%d %d\n", lastmin, lastmin + 1); else printf("%d %d\n", firstmax, firstmax + 1); exit(0); } void k() { int i0 = 1; while (i0 < N && t[i0 - 1] < t[i0]) i0++; if (i0 == N) nope(); vector<int> result; int left = K - 4; if (i0 == 1 || i0 == N - 1) left++; for (int i = 1; i < N; ++i) { if (i0 - 1 <= i && i <= i0 + 1) { result.push_back(i); continue; } if (left) { result.push_back(i); left--; } } puts("TAK"); for (int a : result) printf("%d ", a); puts(""); exit(0); } int main() { scanf("%d%d", &N, &K); for (int i = 0; i < N; ++i) scanf("%d", t + i); if (K == 2) k2(); if (K == 3) k3(); k(); return 0; } |
English