# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
900089 | mannshah1211 | 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 "molecules.h"
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
if (std::accumulate(w.begin(), w.end(), 0LL) < l) {
return {};
}
std::vector<std::pair<int, int>> indices;
for (int i = 0; i < w.size(); i++) {
indices.push_back(std::make_pair(w[i], i));
}
if (indices[0].first > u) {
return {};
}
sort(indices.begin(), indices.end());
int cursum = 0, longest = 0;
for (int i = 0; i < indices.size(); i++) {
cursum += indices[i].first;
if (cursum >= l) {
cursum -= indices[i].first, longest = i;
break;
}
}
for (int i = longest; i < indices.size(); i++) {
cursum += indices[i].first;
cursum -= indices[i - longest].first;
if (cursum >= l && cursum <= u) {
std::vector<int> answer;
for (int j = i; j >= i - longest + 1; j--) {
answer.push_back(indices[j].second);
}
return answer;
}
}
return {};
}