#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL BREAK_VAL = -10000000000000LL; const int MAXN = 512; int main() { ios::sync_with_stdio(false); cin.tie(0); LL a[MAXN]; int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; vector<LL> b; for (int i = 1; i <= n; ++i) { LL s = 0; for (int j = 1; j <= i; ++j) { LL v = a[1]; LL vs = 0; for (int k = 1; k < j; ++k) { vs += b[b.size() - k]; v = min(v, a[k + 1] - vs); } v = min(v, a[j] - vs); s += v; b.push_back(v); } if (s < a[i]) { cout << "NIE" << endl; return 0; } if (i < n) b.push_back(BREAK_VAL); } cout << "TAK\n" << b.size() << "\n"; for (LL v : b) cout << v << " "; cout << endl; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL BREAK_VAL = -10000000000000LL; const int MAXN = 512; int main() { ios::sync_with_stdio(false); cin.tie(0); LL a[MAXN]; int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; vector<LL> b; for (int i = 1; i <= n; ++i) { LL s = 0; for (int j = 1; j <= i; ++j) { LL v = a[1]; LL vs = 0; for (int k = 1; k < j; ++k) { vs += b[b.size() - k]; v = min(v, a[k + 1] - vs); } v = min(v, a[j] - vs); s += v; b.push_back(v); } if (s < a[i]) { cout << "NIE" << endl; return 0; } if (i < n) b.push_back(BREAK_VAL); } cout << "TAK\n" << b.size() << "\n"; for (LL v : b) cout << v << " "; cout << endl; } |