#include <bits/stdc++.h>
#include "molecules.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();
if(l == u) {
if(l%w[0] == 0 && l/w[0] <= n)
return std::vector<int>(l/w[0], w[0]); //all weights equal
}
else if(l == u)
return std::vector<int>(); //no subarray found
int total_weight = 0, i = 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);
while(total_weight < l) {
total_weight += wts[i].wt;
indices.push(wts[i].idx);
i++;
}
i = 0;
while(total_weight > u) {
total_weight -= wts[i--].wt;
indices.pop();
}
if(total_weight < l || total_weight > u) return std::vector<int>(); //no subarray found
std::vector<int> ans(indices.size());
i = 0;
while(!indices.empty()) {
ans[i++] = indices.front();
indices.pop();
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
364 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Contestant can not find answer, jury can |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
364 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
364 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
364 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
364 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
364 KB |
Integer 10 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |