#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;
int n, ans;
int a[501];
int dp[250001];
int cnt[250001];
void calc(int i, int sum) {
for (int j = 0; j <= sum; j++) {
int s = max(j + j - sum, 0LL);
dp[j + a[i]] -= dp[j];
cnt[s] += (dp[j] > 0);
ans += (cnt[s] == n);
}
for (int j = sum; j >= 0; j--) dp[j+a[i]] += dp[j];
}
void solve () {
cin >> n;
int sum = 0;
dp[0] = 1; cnt[0] = n + 1;
for (int i = 1; i <= n; i++) {
cin >> a[i]; sum += a[i];
for (int j = sum; j >= 0; j--) dp[j+a[i]] += dp[j];
}
for (int i = 1; i <= n; i++) calc(i, sum - a[i]);
if (sum & 1 || !dp[sum/2]) {cout << 0; return ;}
cout << ans << '\n';
for (int i = 1; i <= sum; i++) if (cnt[i] == n) 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... |