/** Kajetan Lewandowski **/ #include <bits/stdc++.h> using namespace std; constexpr int LIM = 307; int n; long long a[LIM], b[LIM]; int main() { scanf("%lld", &n); for(int i = 0; i < n; ++i) { scanf("%lld", &a[i]); } b[0] = a[0]; for(int i = 1; i < n; ++i) { b[i] = a[i] - a[i-1]; } long long ts = 0; bool wr = 0; for(int i = 1; i <= n; ++i) { ts = 0; for(int j = 0; j < i; ++j) { ts += b[j]; } if(ts > a[i-1]) { wr = 1; break; } for(int j = i; j < n; ++j) { ts += b[j] - b[j - i]; if(ts > a[i-1]) { wr = 1; break; } } } if(wr) { printf("NIE"); return 0; } printf("TAK\n%d\n", n); for(int i = 0; i < n; ++i) { printf("%lld ", b[i]); } }
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 | /** Kajetan Lewandowski **/ #include <bits/stdc++.h> using namespace std; constexpr int LIM = 307; int n; long long a[LIM], b[LIM]; int main() { scanf("%lld", &n); for(int i = 0; i < n; ++i) { scanf("%lld", &a[i]); } b[0] = a[0]; for(int i = 1; i < n; ++i) { b[i] = a[i] - a[i-1]; } long long ts = 0; bool wr = 0; for(int i = 1; i <= n; ++i) { ts = 0; for(int j = 0; j < i; ++j) { ts += b[j]; } if(ts > a[i-1]) { wr = 1; break; } for(int j = i; j < n; ++j) { ts += b[j] - b[j - i]; if(ts > a[i-1]) { wr = 1; break; } } } if(wr) { printf("NIE"); return 0; } printf("TAK\n%d\n", n); for(int i = 0; i < n; ++i) { printf("%lld ", b[i]); } } |