#include <iostream> #include <bits/stdc++.h> int64_t maximum_sum(std::vector<int64_t>& vec, int n) { std::sort(vec.begin(), vec.end(), std::greater<int>()); int64_t sum = 0; for(int i = 0; i < n; i++) { sum += vec[i]; } return sum; } int64_t maximum_consecutive_sum(std::vector<int64_t>& vec, int n) { int64_t max_sum = 0; for(int i = 0; i <= vec.size() - n; i++) { int64_t range_sum = 0; for(int j = i; j < i + n; j++) { range_sum += vec[j]; } if (range_sum > max_sum) max_sum = range_sum; } return max_sum; } template<class T> void print_vec(std::vector<T> vec) { for(auto &x: vec) std::cout << x << " "; std::cout << std::endl; } void exec_fail() { std::cout << "NIE" << std::endl; exit(0); } int main() { std::iostream::sync_with_stdio(false); int n; std::cin >> n; std::vector<int64_t> a; std::vector<int64_t> output; for(int i = 0; i < n; i++) { int num; std::cin >> num; a.push_back(num); } for(int i = 0; i < n; i++) { auto val = a[i] - maximum_sum(output, i); output.push_back(val); if(val > a[0]) { exec_fail(); } } std::cout << "TAK" << std::endl; std::cout << output.size() << std::endl; print_vec(output); }
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 | #include <iostream> #include <bits/stdc++.h> int64_t maximum_sum(std::vector<int64_t>& vec, int n) { std::sort(vec.begin(), vec.end(), std::greater<int>()); int64_t sum = 0; for(int i = 0; i < n; i++) { sum += vec[i]; } return sum; } int64_t maximum_consecutive_sum(std::vector<int64_t>& vec, int n) { int64_t max_sum = 0; for(int i = 0; i <= vec.size() - n; i++) { int64_t range_sum = 0; for(int j = i; j < i + n; j++) { range_sum += vec[j]; } if (range_sum > max_sum) max_sum = range_sum; } return max_sum; } template<class T> void print_vec(std::vector<T> vec) { for(auto &x: vec) std::cout << x << " "; std::cout << std::endl; } void exec_fail() { std::cout << "NIE" << std::endl; exit(0); } int main() { std::iostream::sync_with_stdio(false); int n; std::cin >> n; std::vector<int64_t> a; std::vector<int64_t> output; for(int i = 0; i < n; i++) { int num; std::cin >> num; a.push_back(num); } for(int i = 0; i < n; i++) { auto val = a[i] - maximum_sum(output, i); output.push_back(val); if(val > a[0]) { exec_fail(); } } std::cout << "TAK" << std::endl; std::cout << output.size() << std::endl; print_vec(output); } |