# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
448380 | tredsused70 | 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.
typedef long long ll;
int find_subset(int l,int u,int mas_[],int n,int ans[])
{
int used[100100]={0},m=0,pos;
array<int,2> mas[100100];
ll sum=0;
for(int i=0;i<n;i++)
mas[i]={mas_[i],i+1};
sort(mas,mas+n);
for(int i=0;i<n;i++)
{
sum+=mas[i][0];
if(sum>u)
{
sum-=mas[i][0];
break;
}
used[mas[i][1]]=1;
ans[m]=mas[i][1];
m++;
if(sum>=l)
return m;
}
for(int i=m-1;i>=0;i--)
{
if(used[mas[n-m+i][1]])
continue;
used[mas[i][1]]=0;
used[mas[n-m+i][1]]=1;
sum-=mas[i][0];
sum+=mas[n-m+i][0];
ans[i]=mas[n-m+i][1];
if(sum>=l)
return m;
}
return 0;
}