# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867169 | StefanL2005 | 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 <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
#define ll long long
int find_subset(int l, int u, vector<int> w, int n, vector<int> result)
{
set<int> Set;
sort(w.begin(), w.end());
if(l < w[0])
return 0;
if (l - u < w[n-1] - w[0])
return 0;
ll sum = 0;
int i = 0;
for (i; i < n; i++)
{
if (sum + w[i] > l)
break;
sum+= w[i];
Set.insert(w[i]);
}
int dif = l - sum;
while (i < n && !(u <= sum && sum <= l))
{
auto poz = Set.lower_bound(w[i] - dif);
if (poz == Set.end())
break;
sum= sum - *poz + w[i];
Set.erase(poz);
Set.insert(w[i]);
i++;
}
if (u <= sum && sum <= l)
{
auto p = Set.begin();
for(i = 0; i < n; i++)
if (w[i] == *p)
{
result.push_back(i);
Set.erase(p);
p = Set.begin();
}
}
for (i = 0; i < result.size(); i++)
cout<< result[i] << " ";
return result.size();
}