# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
849626 | Bach21 | 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 <bits/stdc++.h>
#include "molecules.h"
using namespace std;
#define int long long
const int nmax=2e5+5;
int find_subset(int l, int u, int w[], int n, int result[])
{
pair<int,int> w1[nmax];
for (int i=0;i<n;i++)
{
w1[i].first=w[i];
w1[i].second=i+1;
}
sort(w1,w1+n,greater<pair<int,int>>());
int l1=0;
int r=n-1;
int tmp=0;
while (r>l1)
{
if (tmp+w1[l1].first<=l)
{
tmp+=w1[l1].first;
l1++;
} else if (tmp+w1[l1].first>=l && tmp+w1[l1].first<=u)
{
tmp+=w1[l1].first;
l1++;
} else if (tmp+w1[l1].first>=u)
{
while (tmp<l)
{
tmp+=w1[r].first;
r--;
}
while (tmp>u)
{
tmp-=w1[l1].first;
l1--;
}
}
if (tmp<=u && tmp>=l) break;
}
if (tmp<u || tmp>l) return 0;
int d=0;
for (int i=0;i<l1;i++)
{
result[d]=w1[i].second;
d++;
}
for (int i=r;i<n;i++)
{
result[d]=w1[i].second;
d++;
}
d--;
return d;
}