# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867407 | cheat_when_I_was_young | 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 "molecules.h"
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pair<int,int>> a;
for (int i = 0; i < (int)w.size(); ++i)
a.push_back({w[i], i});
sort(a.begin(), a.end());
queue<int> q;
vector<int> ans;
long long s = 0;
for (int i = 0; i < (int)a.size(); ++i) {
q.push(a[i].second);
s += a[i].first;
if (l <= s && s <= u) break;
while (!q.empty() && s > u) {
s -= w[q.front()];
q.pop();
}
}
if (s < l || s > u) return vector<int>(0);
while (!q.empty()) {
ans.push_back(q.front() + 1);
q.pop();
}
return ans;
}