# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1024098 | vanea | 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;
using ll = long long;
const ll INF = 1e18;
vector<int> find_subset(ll l, ll u, vector<ll> w) {
set<array<ll, 2>, greater<array<ll, 2>>> s;
multiset<pair<ll, int>> w1;
int n = w.size();
s.insert({0, 0});
ll ans = 0;
for(int i = 0; i < n; i++) {
if(w[i] > u) continue;
w1.insert({w[i], i});
auto it = s.lower_bound({u-w[i], INF});
if(it != s.end()) {
ans = max(ans, w[i]+(*it)[0]);
s.insert({(*it)[0]+w[i], w[i]});
}
if((*it)[0] != 0) s.insert({w[i], w[i]});
}
if(ans < l) return {};
vector<int> res;
while(ans != 0) {
auto it = s.lower_bound({ans, INF});
ll curr = (*it)[1];
ans -= curr;
auto it1 = w1.lower_bound({curr, INF});
res.push_back((*it1).second);
w1.erase(it1);
}
sort(res.begin(), res.end());
return res;
}