Untitled
unknown
c_cpp
a year ago
803 B
3
Indexable
#include <iostream>
#include <vector>
#include <set>
#include <bitset>
#include <cstring>
#include <cassert>
typedef long long ll;
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
ll total = (1 << n);
multiset<int> st;
for(int i=0; i<total; i++){
int h;
cin>>h;
st.insert(h);
}
st.erase(st.begin());
vector<int> res;
res.push_back(0);
while(n--){
int cur = *st.begin();
cout<<cur<<' ';
int mxRes = res.size();
for(int i=0; i<mxRes; i++){
auto itr = st.lower_bound(res[i] + cur);
assert(*itr == res[i] + cur);
res.push_back(res[i] + cur);
st.erase(itr);
}
}
assert(st.empty());
return 0;
}
Editor is loading...
Leave a Comment