# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284608 | triplem5ds | Detecting Molecules (IOI16_molecules) | C++14 | 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.
#include "molecules.h"
#include "bits/stdc++.h"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<int> v;
for(int i = 0; i < w.size(); i++)v.push_back(i);
sort(v.begin(),v.end(), [&](int x, int y){return w[x] < w[y];});
if(accumulate(w.begin(),w.end(),0ll) < l || w[v[0]] > u)return vector<int>();
ll sum = 0;
for(int i = 0, j = 0; i < v.size(); i++){
while(j < v.size() && sum < l)sum += w[v[j++]];
if(sum >= l && sum <= u){
vector<int> ret;
for(int k = i; k < j; k++)
ret.push_back(v[k]);
return ret;
}
sum -= w[v[i]];
}
return vector<int>();
}