# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1003541 | Luvidi | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n=w.size();
vector<pll> v;
for(int i=0;i<n;i++){
v.pb({w[i],i});
}
sort(v.begin(),v.end());
ll pre[n+1];
pre[0]=0;
for(int i=1;i<=n;i++)pre[i]=pre[i-1]+v[i-1].fs;
for(int len=1;len<=n;len++){
if(pre[len]>u)continue;
if(pre[n]-pre[n-len]<l)continue;
ll s=pre[len];
vector<int> idx;
for(int i=0;i<len;i++)idx.pb(i);
idx.pb(n);
for(int i=len-1;i>-1;i--){
if(s>=l)break;
idx[i]=idx[i+1]-1;
s-=v[i].fs;
s+=v[idx[i]].fs;
}
idx.pop_back();
for(int &i:idx)i=v[i].sc;
return idx;
}
return std::vector<int>(0);
}