#include <stdio.h> const int MAXN = 300; const int MAXANS = 100*1000; using ll = long long int; ll maxes[MAXN + 1]; ll answer[MAXANS + 1]; int n; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll abs(ll x) { if (x > 0) { return x; } return -x; } int compute() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &maxes[i]); } for (int k = 1; k <= MAXANS; k++) { answer[k] = maxes[1]; } int limit = MAXANS; for (int i = 2; i<=n; i++) { ll cur_sum = 0; for (int k = 1; k < i; k++) { cur_sum += answer[k]; } for (int k = i; k <= MAXANS && k <= limit; k++) { cur_sum += answer[k]; ll difference = cur_sum - maxes[i]; answer[k] -= max(difference, 0l); if (abs(answer[k]) > 1000l * 1000l * 1000l * 1000l * 10l) { limit = k - 1; break; } if (difference > 0 && i == n) { return k; } cur_sum -= answer[k - i + 1]; } } return -1; } int main() { int res = compute(); if (res > 0) { printf("TAK\n"); printf("%d\n", res); for (int i = 1; i <= res; i++) { printf("%lld ", answer[i]); } } else { 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 | #include <stdio.h> const int MAXN = 300; const int MAXANS = 100*1000; using ll = long long int; ll maxes[MAXN + 1]; ll answer[MAXANS + 1]; int n; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll abs(ll x) { if (x > 0) { return x; } return -x; } int compute() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &maxes[i]); } for (int k = 1; k <= MAXANS; k++) { answer[k] = maxes[1]; } int limit = MAXANS; for (int i = 2; i<=n; i++) { ll cur_sum = 0; for (int k = 1; k < i; k++) { cur_sum += answer[k]; } for (int k = i; k <= MAXANS && k <= limit; k++) { cur_sum += answer[k]; ll difference = cur_sum - maxes[i]; answer[k] -= max(difference, 0l); if (abs(answer[k]) > 1000l * 1000l * 1000l * 1000l * 10l) { limit = k - 1; break; } if (difference > 0 && i == n) { return k; } cur_sum -= answer[k - i + 1]; } } return -1; } int main() { int res = compute(); if (res > 0) { printf("TAK\n"); printf("%d\n", res); for (int i = 1; i <= res; i++) { printf("%lld ", answer[i]); } } else { printf("NIE\n"); } } |