# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1267015 | zagaro | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
vector<int> find_subset(int x, int y, vector<ll> w) {
ll l, r, m, n, s, p;
bl B;
n = w.size();
vector<pair<ll,ll> > vec(n+1);
for(int i=1;i<=n;i++)vec[i] = {w[i-1], i-1};
sort(vec.begin(), vec.end());
for(int i=1;i<=n;i++)vec[i].first+=vec[i-1].first;
p= -1;
for(int i=1;i<=n;i++){
B=false;
l=0;
r=(n-i)+1;
wl(l<r-1){
m = (l+r)/2;
s = vec[m+i].first-vec[m].first;
if(s>=x && s <= y){B=true;break;}
else if(s<x)l=m;
else r=m;
}
if(B){p=i;break;}
}
vector<int> res;
if(B){
for(int i=1;i<=p;i++)res.push_back(vec[m+i].second);
}
return res;
}