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;
#include "molecules.h"
std::vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<pair<int, int>> sorted(n);
for (int i = 0; i < n; i++) sorted[i] = make_pair(w[i], i);
sort(sorted.begin(), sorted.end());
int length = 0;
long long sum = 0;
for (; length < n; length++)
{
if (sum + w[length] <= u) {
sum += sorted[length].first;
} else break;
}
vector<int> result(length);
for (int i = 0; i < length; i++)
result[i] = sorted[i].second;
if (sum >= l)
return result;
for (int i = length - 1; i >= 0; i--)
{
sum -= w[result[i]];
result[i] = sorted[n - length + i].second;
sum += w[result[i]];
if (sum >= l)
return result;
}
return std::vector<int>(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |