#include <bits/stdc++.h> using namespace std; int n; long long a[31000], b[31000]; vector <long long> v; const long long inf=(1ll<<40); int main() { scanf("%d", &n); for(int i=1; i<=n; ++i) { scanf("%lld", &b[i]); } for(int i=1; i<=n; ++i) { long long x=(1ll<<30), s=0; for(int j=1; j<=i; ++j) { x=min(x, b[j]-s); s+=a[i-j]; } a[i]=x; } v.push_back(-inf); for(int i=1; i<=n; ++i) { long long s=0, x; for(int j=1; j<i; ++j) { v.push_back(a[j]); s+=a[j]; } x=b[i]-s; if(x>a[i]) { printf("NIE\n"); return 0; } v.push_back(x); v.push_back(-inf); } printf("TAK\n%d\n", (int)v.size()); for(auto xd : v) { printf("%lld ", xd); } 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 | #include <bits/stdc++.h> using namespace std; int n; long long a[31000], b[31000]; vector <long long> v; const long long inf=(1ll<<40); int main() { scanf("%d", &n); for(int i=1; i<=n; ++i) { scanf("%lld", &b[i]); } for(int i=1; i<=n; ++i) { long long x=(1ll<<30), s=0; for(int j=1; j<=i; ++j) { x=min(x, b[j]-s); s+=a[i-j]; } a[i]=x; } v.push_back(-inf); for(int i=1; i<=n; ++i) { long long s=0, x; for(int j=1; j<i; ++j) { v.push_back(a[j]); s+=a[j]; } x=b[i]-s; if(x>a[i]) { printf("NIE\n"); return 0; } v.push_back(x); v.push_back(-inf); } printf("TAK\n%d\n", (int)v.size()); for(auto xd : v) { printf("%lld ", xd); } printf("\n"); return 0; } |