fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long int
  5.  
  6. void solve(){
  7. ll n, i, final;
  8. cin >> n;
  9. final = (1 << n);
  10. // cout << final << " is final\n";
  11. multiset<ll> st;
  12. vector<ll> A,sum;
  13. for(i = 0; i < final; i++){
  14. ll k;
  15. cin >> k;
  16. st.insert(k);
  17. }
  18. for(i=0;i<2;i++){
  19. A.push_back(*st.begin());
  20. sum.push_back(*st.begin());
  21. st.erase(st.begin());
  22. }
  23. while(A.size() < n+1){
  24. ll newElement = *st.begin();
  25. for(auto element:sum){
  26. if(st.find(element+newElement) != st.end()){
  27. st.erase(st.find(element + newElement));
  28. sum.push_back(element + newElement);
  29. }
  30. }
  31. A.push_back(newElement);
  32. }
  33. for(int i=1;i<A.size();i++)
  34. cout << A[i] << ' ';
  35. cout << '\n';
  36.  
  37. }
  38.  
  39. int main(){
  40. ios_base::sync_with_stdio(false);
  41. cin.tie(0); cout.tie(0);
  42. int test;
  43. cin >> test;
  44. while(test--){
  45. solve();
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 4404KB
stdin
2
1
0 10
2
0 1 1 2
stdout
10 
1 1