| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1313942 | voldi9 | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include "molecules.h"
#include <iostream>
#include <vector>
#include <span>
#include <algorithm>
vector<int> map_to_second(span<pair<int,int>> s) {
for (auto &el : s)
res.push_back(el.second);
return res;
}
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pair<int, int>> items(w.size());
for (int i = 0; i < n; i++) {
items[i] = {w[i], i};
}
sort(items.begin(), items.end());
int p1=0, p2=0;
long long sum = 0;
while (p1 < w.size()) {
while (sum < l && p2 < w.size())
sum += items[p2++].first;
while (sum > u && p1 < w.size())
sum -= items[p1++].first;
if (sum >= l)
return map_to_second(span<int>(items.begin() + p1, items.begin() + p2));
else if (p2 >= w.size()) return {};
}
}
