#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
vector<int> ans;
int dp[2501];
int a[501];
void solve () {
int n, s = 0; cin >> n;
for (int i = 1; i <= 2500; i++) ans.pb(i);
dp[0] = 1;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 2500; j >= a[i]; j--) dp[j] += dp[j - a[i]];
s += a[i];
}
if (s % 2 || dp[s / 2] == 0) {cout << 0; return ;}
for (int i = 0; i < n; i++) {
s -= a[i];
for (int j = a[i]; j <= 2500; j++) dp[j] -= dp[j - a[i]];
int j = 0;
while (j < ans.size()) {
if (s < ans[j] || (s - ans[j]) % 2 || !dp[(s - ans[j]) / 2]) {
if (j < ans.size()) swap(ans[j], ans[ans.size()-1]);
ans.pp();
} else j++;
}
s += a[i];
for (int j = 2500; j >= a[i]; j--) dp[j] += dp[j - a[i]];
}
sort(all(ans));
cout << ans.size() << '\n';
for (int i: ans) cout << i << ' ';
}
signed main() {IOS solve(); return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |