#include <cstdio>
#include <vector>
#define PB push_back
#define SIZE(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef vector<LL> VLL;
const LL N = 300;
const LL K = 1e5;
const LL INF = 1e13;
LL n, g[N + 1], mx[N + 1];
VLL r;
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &g[i]);
LL s = 0;
mx[i] = INF;
for (int j = 1; j <= i; ++j) {
mx[i] = min(mx[i], g[j] - s);
s += mx[i - j];
}
}
// for (int i = 0; i <= n; ++i) printf("%lld ", mx[i]);
// puts("");
bool ok = true;
for (int i = 1; i <= n; ++i) {
LL s = 0;
for (int j = 1; j <= i; ++j) {
LL x = mx[min(j, i - j + 1)];
r.PB(x);
s += x;
}
if (s < g[i]) ok = false;
else r.back() -= s - g[i];
if (i < n) r.PB(-INF);
}
if (ok) {
puts("TAK");
printf("%d\n", SIZE(r));
for (int i = 0; i < SIZE(r); ++i) {
printf("%lld%c", r[i], i + 1 < SIZE(r) ? ' ' : '\n');
}
} else {
puts("NIE");
}
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 | #include <cstdio> #include <vector> #define PB push_back #define SIZE(x) (int)(x).size() using namespace std; typedef long long LL; typedef vector<LL> VLL; const LL N = 300; const LL K = 1e5; const LL INF = 1e13; LL n, g[N + 1], mx[N + 1]; VLL r; int main() { scanf("%lld", &n); for (int i = 1; i <= n; ++i) { scanf("%lld", &g[i]); LL s = 0; mx[i] = INF; for (int j = 1; j <= i; ++j) { mx[i] = min(mx[i], g[j] - s); s += mx[i - j]; } } // for (int i = 0; i <= n; ++i) printf("%lld ", mx[i]); // puts(""); bool ok = true; for (int i = 1; i <= n; ++i) { LL s = 0; for (int j = 1; j <= i; ++j) { LL x = mx[min(j, i - j + 1)]; r.PB(x); s += x; } if (s < g[i]) ok = false; else r.back() -= s - g[i]; if (i < n) r.PB(-INF); } if (ok) { puts("TAK"); printf("%d\n", SIZE(r)); for (int i = 0; i < SIZE(r); ++i) { printf("%lld%c", r[i], i + 1 < SIZE(r) ? ' ' : '\n'); } } else { puts("NIE"); } return 0; } |
English