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;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
vector<int> find_subset(int l, int u, vector<int> w) {
int n = (int) w.size();
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) { return w[i] < w[j]; });
long long lo = 0;
long long hi = 0;
for (int i = 1; i <= n; i++) {
lo += w[order[i - 1]];
hi += w[order[n - i]];
if (l <= lo && lo <= u) {
vector<int> res;
for (int j = 0; j < i; j++) {
res.emplace_back(order[j] + 1);
}
return res;
} else if (l <= hi && hi <= u) {
vector<int> res;
for (int j = 0; j < i; j++) {
res.emplace_back(order[n - 1 - j] + 1);
}
return res;
} else if (lo < l && u < hi) {
vector<int> res;
for (int j = 0; j < i; j++) {
res.emplace_back(order[j] + 1);
}
long long sum = lo;
for (int j = i - 1; j >= 0; j--) {
if (sum - w[order[j]] + w[order[n - 1 - j]] < l) {
res[j] = order[n - 1 - j] + 1;
sum -= w[order[j]];
sum += w[order[n - 1 - j]];
continue;
}
sum -= w[order[j]];
for (int k = j; k <= n - 1 - j; k++) {
if (sum + w[order[k]] >= l) {
res[j] = order[k] + 1;
break;
}
}
break;
}
return res;
}
}
return vector<int>();
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
debug(find_subset(15, 17, {6, 8, 8, 7}));
debug(find_subset(14, 15, {5, 5, 6, 6}));
debug(find_subset(10, 20, {15, 17, 16, 18}));
return 0;
}
#endif
# | 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... |