fork download
  1. /*
  2.   shool : Cu Chi High School
  3.   participant : Ngo Quoc Binh
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. #define debug(x) cerr << #x << " = " << x << "\n";
  9. #define vdebug(a) cerr << #a << " = "; for(auto x : a) cout << x << " "; cout << "\n";
  10. #define TIME cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  11. #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  12. #define hashmap unordered_map
  13. #define hashset unordered_set
  14. #define all(x) (x).begin(),(x).end()
  15. #define rall(x) (x).rbegin(),(x).rend()
  16. #define rev(x) reverse(all(x))
  17. #define sz(x) ((int)((x).size()))
  18. #define max_arr(x) *max_element(all(x))
  19. #define min_arr(x) *min_element(all(x))
  20.  
  21. #define pb push_back
  22. #define pf push_front
  23. #define PB pop_back
  24. #define PF pop_front
  25. #define en '\n'
  26. #define ff first
  27. #define ss second
  28. #define task "wtf"
  29.  
  30. using ll = long long;
  31. using ull = unsigned long long;
  32. using ld = long double;
  33.  
  34. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  35.  
  36. void solve()
  37. {
  38. int t;
  39. cin >> t;
  40.  
  41. while(t--)
  42. {
  43. int n,u,m;
  44. cin >> n >> u >> m;
  45.  
  46. vector<ll> a(n);
  47. for(int i = 0 ; i < n ; i++) cin >> a[i];
  48.  
  49. ll sum = accumulate(all(a),0);
  50. bitset<1000005> dp;
  51. dp[0] = 1;
  52. for(int i = 0 ; i < n ; i++)
  53. {
  54. dp |= (dp << a[i]);
  55. }
  56.  
  57. for(int i = 0 ; i <= sum ; i++)
  58. {
  59. if(dp[i])
  60. {
  61. cout << i << " ";
  62. }
  63. }
  64. }
  65. }
  66.  
  67. int main()
  68. {
  69. fastIO
  70.  
  71. solve();
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5320KB
stdin
1
5 2 3
2 7 3 6 6
stdout
0 2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 24