# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
403290 | Leonardo_Paes | 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.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
vector<int> find_subset(int ll, int u, vector<int> w){
vector<int> ans;
vector<pair<int,int>> v(w.size());
for(int i=0; i<v.size(); i++) v[i] = {w[i], i};
sort(v.begin(), v.end());
int l = 0, r = 0, sum = v[0].f;
while(l < v.size()){
if(ll <= sum and sum <= u) break;
if(sum < ll){
if(r+1 < v.size()) sum += v[++r];
else break;
}
else if(sum > ll) sum -= v[l++].f;
}
if(sum < ll or sum > u) return ans;
while(l <= r) ans.push_back(v[l++].s);
return ans;
}