#include <bits/stdc++.h> using namespace std; #define JOIN_(X, Y) X##Y #define JOIN(X, Y) JOIN_(X, Y) #define TMP JOIN(tmp, __LINE__) #define PB push_back #define SZ(x) int((x).size()) #define REP(i, n) for (int i = 0, TMP = (n); i < TMP; ++i) #define FOR(i, a, b) for (int i = (a), TMP = (b); i <= TMP; ++i) #define FORD(i, a, b) for (int i = (a), TMP = (b); i >= TMP; --i) #ifdef DEBUG #define DEB(x) (cerr << x) #else #define DEB(x) #endif typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const ll INF = 1e13; ll in[303] = {}; ll out[303] = {}; ll sum_out(int a, int b) { ll result = 0; FOR(i, a, b) { result += out[i]; } return result; } void inline one() { int n; cin >> n; bool ok = true; ll sum = 0; REP(i, n) { ll x; cin >> x; in[i] = x; if (i == 0) { out[i] = x; } else { ll upper_limit = INF; REP(j, i) { ll upper_limit_candidate = in[j] - sum_out(i - j, i - 1); upper_limit = min(upper_limit, upper_limit_candidate); } ll out_candidate = x - sum_out(0, i - 1); if (out_candidate <= upper_limit) { out[i] = out_candidate; } else { ok = false; break; } } sum += x; } if (ok) { vector<ll> result; REP(i, n) { if (i > 0) { result.PB(-INF); } REP(j, i + 1) { result.PB(out[j]); } } cout << "TAK\n"; cout << SZ(result) << "\n"; for (const auto &x : result) { cout << x << " "; } cout << "\n"; } else { cout << "NIE\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(0); // int z; cin >> z; while(z--) one(); }
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 81 82 83 84 85 86 87 | #include <bits/stdc++.h> using namespace std; #define JOIN_(X, Y) X##Y #define JOIN(X, Y) JOIN_(X, Y) #define TMP JOIN(tmp, __LINE__) #define PB push_back #define SZ(x) int((x).size()) #define REP(i, n) for (int i = 0, TMP = (n); i < TMP; ++i) #define FOR(i, a, b) for (int i = (a), TMP = (b); i <= TMP; ++i) #define FORD(i, a, b) for (int i = (a), TMP = (b); i >= TMP; --i) #ifdef DEBUG #define DEB(x) (cerr << x) #else #define DEB(x) #endif typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const ll INF = 1e13; ll in[303] = {}; ll out[303] = {}; ll sum_out(int a, int b) { ll result = 0; FOR(i, a, b) { result += out[i]; } return result; } void inline one() { int n; cin >> n; bool ok = true; ll sum = 0; REP(i, n) { ll x; cin >> x; in[i] = x; if (i == 0) { out[i] = x; } else { ll upper_limit = INF; REP(j, i) { ll upper_limit_candidate = in[j] - sum_out(i - j, i - 1); upper_limit = min(upper_limit, upper_limit_candidate); } ll out_candidate = x - sum_out(0, i - 1); if (out_candidate <= upper_limit) { out[i] = out_candidate; } else { ok = false; break; } } sum += x; } if (ok) { vector<ll> result; REP(i, n) { if (i > 0) { result.PB(-INF); } REP(j, i + 1) { result.PB(out[j]); } } cout << "TAK\n"; cout << SZ(result) << "\n"; for (const auto &x : result) { cout << x << " "; } cout << "\n"; } else { cout << "NIE\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(0); // int z; cin >> z; while(z--) one(); } |