#include <ctime> #include <cassert> #include <iostream> #include <iomanip> #include <vector> #include <algorithm> using namespace std; const int MAXN = 300; const int MAXK = 100000; const long long MINV = -9223372036854775807; const long long MAXV = 9223372036854775807; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) long long lim[MAXN]; long long s[MAXN]; long long seq[MAXK]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; FOR (i, n) { cin >> lim[i]; } int k = n; FOR (i, k) { long long lowest = MAXV; FOR (d, n) { if (i - d - 1 >= 0) s[d] -= seq[i-d-1]; } FOR (d, n) { if (d <= i) { long long val = lim[d] - s[d]; lowest = min(lowest, val); } } seq[i] = lowest; FOR (d, n) { s[d] += lowest; } } bool ok = true; FOR (i, n) { long long sum = 0; long long best = MINV; FOR (j, k) { sum += seq[j]; if (j - (i + 1) >= 0) { sum -= seq[j - (i + 1)]; } if (j >= i) { best = max(best, sum); } } if (best != lim[i]) ok = false; } if (!ok) { cout << "NIE" << endl; // cout << k << endl; // FOR (d, n) { // cout << seq[d] << " "; // } // cout << endl; } else { cout << "TAK" << endl; cout << k << endl; FOR (d, n) { cout << seq[d] << " "; } cout << endl; } 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include <ctime> #include <cassert> #include <iostream> #include <iomanip> #include <vector> #include <algorithm> using namespace std; const int MAXN = 300; const int MAXK = 100000; const long long MINV = -9223372036854775807; const long long MAXV = 9223372036854775807; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) long long lim[MAXN]; long long s[MAXN]; long long seq[MAXK]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; FOR (i, n) { cin >> lim[i]; } int k = n; FOR (i, k) { long long lowest = MAXV; FOR (d, n) { if (i - d - 1 >= 0) s[d] -= seq[i-d-1]; } FOR (d, n) { if (d <= i) { long long val = lim[d] - s[d]; lowest = min(lowest, val); } } seq[i] = lowest; FOR (d, n) { s[d] += lowest; } } bool ok = true; FOR (i, n) { long long sum = 0; long long best = MINV; FOR (j, k) { sum += seq[j]; if (j - (i + 1) >= 0) { sum -= seq[j - (i + 1)]; } if (j >= i) { best = max(best, sum); } } if (best != lim[i]) ok = false; } if (!ok) { cout << "NIE" << endl; // cout << k << endl; // FOR (d, n) { // cout << seq[d] << " "; // } // cout << endl; } else { cout << "TAK" << endl; cout << k << endl; FOR (d, n) { cout << seq[d] << " "; } cout << endl; } return 0; } |