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>
struct weights {
int wt;
int idx;
};
bool cmp(weights a, weights b) {
return (a.wt < b.wt);
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
int total_weight = 0, a = 0;
std::queue<int> indices;
std::vector<struct weights> wts(n);
for(int i = 0; i < n; i++)
wts[i] = {w[i], i};
std::sort(wts.begin(), wts.end(), cmp);
int i = 0, j = 0;
while(i < n || j < n) {
if(total_weight < l) {
total_weight += wts[j].wt;
indices.push(wts[j++].idx);
if(j >= n) break;
}
else if(total_weight > u) {
total_weight -= wts[i++].wt;
indices.pop();
if(i >= n) break;
}
else break;
}
if(total_weight < l || total_weight > u) return std::vector<int>(); //no subarray found
std::vector<int> ans(indices.size());
while(!indices.empty()) {
ans[a++] = indices.front();
indices.pop();
}
return ans;
}
# | 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... |