# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936787 | 4QT0R | 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;
#define ll long long
vector<ll> find_subset(ll l, ll u, vector<ll> w){
ll n=w.size(),sm=0;
vector<ll> ans;
vector<pair<ll,ll>> cp;
for (int i = 0; i<n; i++){
sm+=w[i];
cp.push_back({w[i],i});
}
sort(cp.begin(),cp.end());
if (sm<l)return {};
set<pair<ll,ll>> s;
sm=0;
for (int i = 0; i<n; i++){
sm+=cp[i].first;
s.insert(cp[i]);
if (l<=sm && sm<=u){
for (auto u : s)ans.push_back(u.second);
break;
}
if (sm>u){
auto it = s.lower_bound({u-sm,-1});
if (it==s.end())it--;
sm-=it->first;
s.erase(it);
}
if (l<=sm && sm<=u){
for (auto u : s)ans.push_back(u.second);
break;
}
}
return ans;
}