#include <bits/stdc++.h> using namespace std; bool check(const vector<int>& a, const vector<int>& b) { const auto n = a.size(); const auto m = b.size(); for (size_t len = 1; len <= n; len++) { auto mx = numeric_limits<int>::min(); for (size_t l = 0; l + len <= m; l++) { auto r = l + len; auto sum = 0; for (size_t i = l; i < r; i++) { sum += b[i]; } mx = max(sum, mx); } if (mx != a[len - 1]) { return false; } } return true; } bool check_fast(const vector<int>& a, const vector<int>& b) { const auto n = a.size(); const auto m = b.size(); for (size_t len = 1; len <= n; len++) { auto sum = 0; for (size_t i = 0; i < len; i++) { sum += b[i]; } auto mx = sum; for (size_t i = len; i < m; i++) { sum += b[i]; sum -= b[i - len]; mx = max(mx, sum); } if (mx != a[len - 1]) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (auto &x : a) { cin >> x; } vector<int> result(n); result[0] = a[0]; for (int i = 1; i < n ; i++) { result[i] = a[i] - a[i - 1]; } if (check_fast(a, result)) { cout << "TAK\n"; cout << n << "\n"; for (auto x : result) { cout << x << " "; } cout << "\n"; } else { 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include <bits/stdc++.h> using namespace std; bool check(const vector<int>& a, const vector<int>& b) { const auto n = a.size(); const auto m = b.size(); for (size_t len = 1; len <= n; len++) { auto mx = numeric_limits<int>::min(); for (size_t l = 0; l + len <= m; l++) { auto r = l + len; auto sum = 0; for (size_t i = l; i < r; i++) { sum += b[i]; } mx = max(sum, mx); } if (mx != a[len - 1]) { return false; } } return true; } bool check_fast(const vector<int>& a, const vector<int>& b) { const auto n = a.size(); const auto m = b.size(); for (size_t len = 1; len <= n; len++) { auto sum = 0; for (size_t i = 0; i < len; i++) { sum += b[i]; } auto mx = sum; for (size_t i = len; i < m; i++) { sum += b[i]; sum -= b[i - len]; mx = max(mx, sum); } if (mx != a[len - 1]) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (auto &x : a) { cin >> x; } vector<int> result(n); result[0] = a[0]; for (int i = 1; i < n ; i++) { result[i] = a[i] - a[i - 1]; } if (check_fast(a, result)) { cout << "TAK\n"; cout << n << "\n"; for (auto x : result) { cout << x << " "; } cout << "\n"; } else { cout << "NIE\n"; } } |