| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 840177 | sleepntsheep | 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 <algorithm>
#include <set>
#include <deque>
int find_subset(int l, int u, int *w, int n, int *result)
{
std::sort(w, w+n);
int s = 0, i;
std::multiset<int> sub;
std::deque<int> lo, hi;
for (i = 0; i < n; ++i) if (s + w[i] < l) s += w[i], lo.push_back(w[i]), sub.insert(i); else break;
for (int j = i; j < n; ++j) hi.push_back(w[j]);
while (s < l && lo.size() && hi.size())
{
int d = hi.front() - lo.front();
s += d;
sub.erase(sub.find(lo.front())); sub.insert(hi.front()); hi.pop_front(); lo.pop_front();
}
if (s < l) return 0;
int j = 0;
for (auto x : sub) result[j++] = x;
return j;
}
