#include <cstdio>
#include <vector>
#include <algorithm>
const int N = 500005;
int n, k, mn[N], a[N], prev;
void out(int x) {
prev += x;
if (prev != n) {
if (prev - x) printf(" ");
printf("%d", prev);
}
}
void rusz(int x) {
while (x > 1 && k) {
--x;
--k;
out(1);
}
if (x) out(x);
}
std::vector<int> ans;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) scanf("%d", a + i);
if (k == 2) {
mn[0] = ~(1 << 31);
for (int i = 0; i < n; ++i) mn[i + 1] = std::min(mn[i], a[i]);
int mx = 0;
for (int i = n - 1; i > 0; --i) {
mx = std::max(mx, a[i]);
if (mn[i] >= mx) {
printf("TAK\n%d\n", i);
return 0;
}
}
printf("NIE\n");
return 0;
}
if (k == 3) {
int ind = 0;
for (int i = 1; i < n; ++i) if (a[i] <= a[ind]) ind = i;
if (ind) {
ans.push_back(ind);
ans.push_back(1);
if (n - ind - 1) ans.push_back(n - ind - 1);
} else {
ind = 0;
for (int i = 1; i < n; ++i) if (a[i] > a[ind]) ind = i;
if (ind != n - 1) {
if (ind) ans.push_back(ind);
ans.push_back(1);
ans.push_back(n - ind - 1);
}
}
} else {
for (int i = 0; i + 1 < n && ans.empty(); ++i) {
if (a[i] >= a[i + 1]) {
if (i) ans.push_back(i);
ans.push_back(1);
ans.push_back(1);
if (n - i - 2) ans.push_back(n - i - 2);
}
}
}
if (ans.empty()) printf("NIE\n");
else {
printf("TAK\n");
k -= ans.size();
for (int i = 0; i < (int)ans.size(); ++i) rusz(ans[i]);
printf("\n");
}
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 | #include <cstdio> #include <vector> #include <algorithm> const int N = 500005; int n, k, mn[N], a[N], prev; void out(int x) { prev += x; if (prev != n) { if (prev - x) printf(" "); printf("%d", prev); } } void rusz(int x) { while (x > 1 && k) { --x; --k; out(1); } if (x) out(x); } std::vector<int> ans; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", a + i); if (k == 2) { mn[0] = ~(1 << 31); for (int i = 0; i < n; ++i) mn[i + 1] = std::min(mn[i], a[i]); int mx = 0; for (int i = n - 1; i > 0; --i) { mx = std::max(mx, a[i]); if (mn[i] >= mx) { printf("TAK\n%d\n", i); return 0; } } printf("NIE\n"); return 0; } if (k == 3) { int ind = 0; for (int i = 1; i < n; ++i) if (a[i] <= a[ind]) ind = i; if (ind) { ans.push_back(ind); ans.push_back(1); if (n - ind - 1) ans.push_back(n - ind - 1); } else { ind = 0; for (int i = 1; i < n; ++i) if (a[i] > a[ind]) ind = i; if (ind != n - 1) { if (ind) ans.push_back(ind); ans.push_back(1); ans.push_back(n - ind - 1); } } } else { for (int i = 0; i + 1 < n && ans.empty(); ++i) { if (a[i] >= a[i + 1]) { if (i) ans.push_back(i); ans.push_back(1); ans.push_back(1); if (n - i - 2) ans.push_back(n - i - 2); } } } if (ans.empty()) printf("NIE\n"); else { printf("TAK\n"); k -= ans.size(); for (int i = 0; i < (int)ans.size(); ++i) rusz(ans[i]); printf("\n"); } return 0; } |
English