#include<bits/stdc++.h> using namespace std; using lld = long long; const lld INF = 1e13; int main(void){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<lld> t(n); for(lld& i : t) cin >> i; vector<lld> res; for(int i=0;i<n;i++){ lld x = t[i] / (lld) (i+1); for(int j=0;j<=i;j++) res.push_back(x); res.back() -= (lld) (i+1) * x - t[i]; res.push_back(-INF); } vector<lld> val(n,-INF); for(int i=0;i<n;i++){ lld sum = 0; for(int j=0;j<i;j++) sum += res[j]; for(int j=i;j<res.size();j++){ sum += res[j]; val[i] = max(val[i], sum); sum -= res[j-i]; } } if(val != t){ cout << "NIE\n"; return 0; } cout << "TAK\n"; cout << res.size() << "\n"; for(lld& i : res) cout << i << " "; cout << "\n"; 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 | #include<bits/stdc++.h> using namespace std; using lld = long long; const lld INF = 1e13; int main(void){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<lld> t(n); for(lld& i : t) cin >> i; vector<lld> res; for(int i=0;i<n;i++){ lld x = t[i] / (lld) (i+1); for(int j=0;j<=i;j++) res.push_back(x); res.back() -= (lld) (i+1) * x - t[i]; res.push_back(-INF); } vector<lld> val(n,-INF); for(int i=0;i<n;i++){ lld sum = 0; for(int j=0;j<i;j++) sum += res[j]; for(int j=i;j<res.size();j++){ sum += res[j]; val[i] = max(val[i], sum); sum -= res[j-i]; } } if(val != t){ cout << "NIE\n"; return 0; } cout << "TAK\n"; cout << res.size() << "\n"; for(lld& i : res) cout << i << " "; cout << "\n"; return 0; } |