# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
774580 | JMs | 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;
int *find_subset(int l, int u, int w[], int n, int result[])
{
unsigned const long long tam = 100005;
long long v[tam], aux, c=0, ph, pl, s;
for( long long i=0; i<n; i++){
v[i]=i;
}
for( long long i=0; i<n-1; i++){
for( long long j=i+1; j<n; j++){
if(w[i]>w[j]){
aux=w[j];
w[j]=w[i];
w[i]=aux;
aux=v[j];
v[j]=v[i];
v[i]=aux;
}
}
}
pl=0;
ph=0;
s=w[0];
while(1){
//cout<<pl<<" "<<ph<<" "<<s<<endl;
if(s<l && ph<n-1){
ph++;
s+=w[ph];
}
else if(s>u && pl<ph){
s-=w[pl];
pl++;
}
else if( ph==n-1 && (s>u || s<l)){
return result;
break;
}
else{
for( long long i=pl; i<=ph; i++){
result[c]=v[i];
c++;
cout<<v[i]<<" ";
}
cout<<endl;
break;
}
}
return result;
}