#include <iostream> #include <vector> using namespace std; int n; int gain[300]; int solution[300]; bool solve() { int current = 0; for (int i = 0; i < n; i++) { solution[i] = gain[i] - current; current += solution[i]; int sum = 0; for (int j = i; j >= 0; j--) { sum += solution[j]; if (sum > gain[i - j]) { return false; } } } return true; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> gain[i]; } bool possible = solve(); if (possible) { cout << "TAK" << endl; cout << n << endl; for (int i = 0; i < n; i++) { cout << solution[i] << " "; } } else { cout << "NIE"; } 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 | #include <iostream> #include <vector> using namespace std; int n; int gain[300]; int solution[300]; bool solve() { int current = 0; for (int i = 0; i < n; i++) { solution[i] = gain[i] - current; current += solution[i]; int sum = 0; for (int j = i; j >= 0; j--) { sum += solution[j]; if (sum > gain[i - j]) { return false; } } } return true; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> gain[i]; } bool possible = solve(); if (possible) { cout << "TAK" << endl; cout << n << endl; for (int i = 0; i < n; i++) { cout << solution[i] << " "; } } else { cout << "NIE"; } return 0; } |