#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) cerr << "TRACE(" #x ")" << endl; #define DEBUG(x) cerr << #x << " = " << (x) << endl; typedef long long LL; typedef unsigned long long ULL; struct Impossible {}; class Limits { public: void read(); vector<LL> generate_example() const; private: int max_len; vector<LL> max_sum; }; void Limits::read() { cin >> max_len; max_sum.resize(max_len + 1); FOR(len,1,max_len) cin >> max_sum[len]; } vector<LL> Limits::generate_example() const { vector<LL> example(max_len); LL sum = 0; FOR(len, 1, max_len) { example[len-1] = max_sum[len] - sum; sum = 0; FOR(small_len, 1, len) { sum += example[len-small_len]; if (sum > max_sum[small_len]) throw Impossible{}; } assert(sum == max_sum[len]); } return example; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Limits limits; limits.read(); try { vector<LL> example = limits.generate_example(); cout << "TAK\n"; cout << example.size() << "\n"; for (LL x : example) cout << x << " "; cout << "\n"; } catch (Impossible) { cout << "NIE\n"; } }
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 | #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) cerr << "TRACE(" #x ")" << endl; #define DEBUG(x) cerr << #x << " = " << (x) << endl; typedef long long LL; typedef unsigned long long ULL; struct Impossible {}; class Limits { public: void read(); vector<LL> generate_example() const; private: int max_len; vector<LL> max_sum; }; void Limits::read() { cin >> max_len; max_sum.resize(max_len + 1); FOR(len,1,max_len) cin >> max_sum[len]; } vector<LL> Limits::generate_example() const { vector<LL> example(max_len); LL sum = 0; FOR(len, 1, max_len) { example[len-1] = max_sum[len] - sum; sum = 0; FOR(small_len, 1, len) { sum += example[len-small_len]; if (sum > max_sum[small_len]) throw Impossible{}; } assert(sum == max_sum[len]); } return example; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Limits limits; limits.read(); try { vector<LL> example = limits.generate_example(); cout << "TAK\n"; cout << example.size() << "\n"; for (LL x : example) cout << x << " "; cout << "\n"; } catch (Impossible) { cout << "NIE\n"; } } |