# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
678894 | Genius3435 | 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;
using u32 = uint32_t;
int[] find_subset(int l, int u, int[] _w) {
int const n = sizeof(w)/sizeof(int);
deque<pair<u32, int>> w, used;
for (int i = 0; i < n; ++i) {
w.emplace_back(_w[i], i);
}
sort(w.begin(), w.end());
u32 s = 0;
while (s < l && !w.empty()) {
auto const [x, i] = w.front();
if (s+x > u) break;
w.pop_front();
used.emplace_back(x, i);
s += x;
}
while (s < l && !w.empty()) {
auto const [x, i] = used.front();
auto const [y, j] = w.back();
s -= x, s += y;
used.pop_front();
w.pop_back();
used.emplace_back(y, j);
}
if (l <= s && s <= u) {
int *ans = new int[used.size()], j = 0;
for (auto const &[x, i] : used) ans[j++] = i;
return ans;
}
else {
int *ans = new int[0];
return ans;
}
}