Iamtui1010

moneysum.cpp

Sep 14th, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<map>
  3. #include<vector>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     cin.tie(0)->sync_with_stdio(0);
  13.     long n;
  14.     cin >> n;
  15.     map<long, long> tic;
  16.     while (n--){
  17.         long x;
  18.         cin >> x;
  19.         vector<long> sum;
  20.         for (auto i : tic)
  21.             sum.push_back(i.first+x);
  22.         for (auto i : sum)
  23.             tic[i] = 1;
  24.         tic[x] = 1;
  25.     }
  26.     cout << tic.size() << nln;
  27.     for (auto i : tic)
  28.         cout << i.first << ' ';
  29.     cout << nln;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment