# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
774995 | Minindu2006 | 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 "grader.cpp"
#include<bits/stdc++.h>
using namespace std;
std::vector<int> find_subset(int L, int U, std::vector<int> w)
{
vector<pair<int, int>> arr;
for(int i=0;i<(int)w.size();i++)
arr.push_back({w[i], i});
sort(arr.begin(), arr.end());
int p1 = 0, p2 = 0, pos = 0;
long long sum = arr[0].first;
while(p1 < (int)w.size())
{
if(sum >= L && sum <= U)
{
pos = 1;
break;
}
else if(sum < L)
{
p1++;
if(p1 == (int)w.size())
sum += arr[p1].first;
}
else if(sum > U)
{
sum -= arr[p2].first;
p2++;
}
}
vector<int> ans;
if(!pos)
return ans;
for(int i=p2;i<=p1;i++)
ans.push_back(arr[i].second);
return ans;
}