Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = 100000;
- int a[maxn];
- int s[maxn + 1];
- int b[maxn];
- int n;
- void find_result(int pos, int target) {
- if (pos == -1) {
- assert(target == 0);
- return;
- }
- if (s[pos] >= abs(target - a[pos])) {
- b[pos] = 1;
- find_result(pos - 1, target - a[pos]);
- } else {
- b[pos] = -1;
- find_result(pos - 1, target + a[pos]);
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- ifstream in("hell.in");
- ofstream out("hell.out");
- in >> n;
- for (int i = 0; i < n; ++i) {
- in >> a[i];
- }
- partial_sum(a, a + n, s + 1);
- if (accumulate(a, a + n, 0) % 2 == 0) {
- find_result(n - 1, 0);
- out << "Yes\n";
- for (int i = 0; i < n; ++i) {
- out << b[i] << ' ';
- }
- } else {
- out << "No\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement