fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const long long MaxN = 1e2 + 5, MaxV=1e5+5;
  4. long long n, a[MaxN], dp[MaxV];
  5. void input()
  6. {
  7. cin >> n;
  8. for (long long i=1; i<=n; i++)
  9. {
  10. cin >> a[i];
  11. }
  12. }
  13. void solve()
  14. {
  15. memset(dp,0,sizeof(dp));
  16. long long cnt =0;
  17. dp[0]=1;
  18. for (long long i=1; i<=n; i++)
  19. {
  20. for (long long j=MaxV; j>=0; j--)
  21. {
  22. if(dp[j]==1&&dp[j+a[i]]==0)
  23. {
  24. dp[j+a[i]]=1;
  25. cnt++;
  26. }
  27.  
  28. }
  29. }
  30. cout << cnt << "\n";
  31. for (long long i=1; i<=MaxV; i++)
  32. {
  33. if(dp[i]==1)
  34. {
  35. cout << i << " ";
  36. }
  37. }
  38. }
  39. int main()
  40. {
  41. ios_base::sync_with_stdio(0);
  42. cin.tie(0);
  43. input();
  44. solve();
  45. }
  46.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
0