Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int N;
- cin >> N;
- vector < int > a(N);
- int sum = 0;
- for(int& x : a) {
- cin >> x;
- sum += x;
- }
- vector < bool > dp(32768);
- int ans = 0;
- for(int x : a) {
- for(int i = sum; i >= 0; --i)
- if(dp[i]) {
- if(!dp[i + x])
- ++ans;
- dp[i + x] = true;
- }
- if(!dp[x]) {
- ++ans;
- dp[x] = true;
- }
- }
- cout << ans;
- }
Add Comment
Please, Sign In to add comment