# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
453653 | ponytail | 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.
vector<int> find_subset(int l, int u, vector<int> w){
ll n,l,u;
cin >> n >> l>>u;
pair<ll,ll> w[n];
bool used[n];
ll tot_sum=0;
for(int i=0;i<n;i++)cin>>w[i].first;
for(int i=0;i<n;i++)w[i].second=i;
for(int i=0;i<n;i++)tot_sum+=w[i].first;
for(int i=0;i<n;i++)used[i]=false;
sort(w,w+n);
ll curr_sum=0, pt=0, nani=0;
for(int i=0;i<n;i++){
curr_sum+=w[i].first;
if(u<curr_sum){
curr_sum-=w[i].first;
pt=i;
break;
}
used[i]=true;
nani++;
if(l<=curr_sum&&curr_sum<=u){
vector<int> ans;
for(int j=0;j<n;j++){
if(used[j]) ans.push_back(w[j].second);
}
return ans;
}
}
for(int i=0;i<min(n-pt,pt);i++){
curr_sum-=w[i].first;
used[i]=false;
curr_sum+=w[n-i-1].first;
used[n-i-1]=true;
if(l<=curr_sum&&curr_sum<=u){
break;
}
}
if(l<=curr_sum&&curr_sum<=u){
vector<int> ans;
for(int j=0;j<n;j++){
if(used[j]) ans.push_back(w[j].second);
}
return ans;
}
else{
return {};
}
}