#include<cstdio> const long long NEG_INF = -10000000000000LL; long long seq[333]; long long incr[333]; long long partial[333]; int k; bool solve() { long long sum = 0LL; long long cur_max; cur_max = NEG_INF; for (int i = 0; i < k; ++i) { partial[i] = seq[i]; sum += seq[i]; if (cur_max < partial[i]) cur_max = partial[i]; } if (incr[0] != cur_max || incr[k - 1] != sum) return false; for (int j = 1; j < k - 1; ++j) { cur_max = NEG_INF; for (int i = 0; i < k - j; ++i) { partial[i] += seq[i + j]; if (cur_max < partial[i]) cur_max = partial[i]; } if (incr[j] != cur_max) return false; } return true; } int main() { scanf("%d", &k); scanf("%lld", &incr[0]); seq[0] = incr[0]; for (int i = 1; i < k; ++i) { scanf("%lld", &incr[i]); seq[i] = incr[i] - incr[i - 1]; } if (solve()) { printf("TAK\n%d\n", k); for (int i = 0; i < k; ++i) printf("%lld%c", seq[i], i == k - 1 ? '\n' : ' '); } else printf("NIE\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 | #include<cstdio> const long long NEG_INF = -10000000000000LL; long long seq[333]; long long incr[333]; long long partial[333]; int k; bool solve() { long long sum = 0LL; long long cur_max; cur_max = NEG_INF; for (int i = 0; i < k; ++i) { partial[i] = seq[i]; sum += seq[i]; if (cur_max < partial[i]) cur_max = partial[i]; } if (incr[0] != cur_max || incr[k - 1] != sum) return false; for (int j = 1; j < k - 1; ++j) { cur_max = NEG_INF; for (int i = 0; i < k - j; ++i) { partial[i] += seq[i + j]; if (cur_max < partial[i]) cur_max = partial[i]; } if (incr[j] != cur_max) return false; } return true; } int main() { scanf("%d", &k); scanf("%lld", &incr[0]); seq[0] = incr[0]; for (int i = 1; i < k; ++i) { scanf("%lld", &incr[i]); seq[i] = incr[i] - incr[i - 1]; } if (solve()) { printf("TAK\n%d\n", k); for (int i = 0; i < k; ++i) printf("%lld%c", seq[i], i == k - 1 ? '\n' : ' '); } else printf("NIE\n"); return 0; } |