#include <iostream> #include <vector> int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::vector<long long> A(n); for (int i = 0; i < n; ++i) { std::cin >> A[i]; } std::vector<long long> reqs(n + 1); reqs[0] = 0; for (int j = 1; j < n + 1; ++j) { reqs[j] = 1e18; } for (int j = 0; j < n + 1; ++j) { if (j > 0) { if (reqs[j] != A[j - 1]) { std::cout << "NIE"; return 0; } } for (int k = j + 1; k < n + 1; ++k) { reqs[k] = std::min(reqs[k], reqs[j] + A[k - j - 1]); } } std::cout << "TAK\n" << n << "\n"; for (int i = 0; i < n; ++i) { std::cout << A[i] - (i > 0 ? A[i - 1] : 0) << " "; } 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 | #include <iostream> #include <vector> int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::vector<long long> A(n); for (int i = 0; i < n; ++i) { std::cin >> A[i]; } std::vector<long long> reqs(n + 1); reqs[0] = 0; for (int j = 1; j < n + 1; ++j) { reqs[j] = 1e18; } for (int j = 0; j < n + 1; ++j) { if (j > 0) { if (reqs[j] != A[j - 1]) { std::cout << "NIE"; return 0; } } for (int k = j + 1; k < n + 1; ++k) { reqs[k] = std::min(reqs[k], reqs[j] + A[k - j - 1]); } } std::cout << "TAK\n" << n << "\n"; for (int i = 0; i < n; ++i) { std::cout << A[i] - (i > 0 ? A[i - 1] : 0) << " "; } return 0; } |