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"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> find_subset(int _l, int _u, vector<int> w) {
ll l = _l, u = _u;
int n = w.size();
if (n == 1) {
if (w[0] >= l && w[0] <= u)
return {0};
return {};
}
vector<int> idxs(n);
iota(idxs.begin(), idxs.end(), 0);
sort(idxs.begin(), idxs.end(), [&](int i, int j){ return w[i] < w[j]; });
vector<int> ans;
ll s = 0;
int small = w[idxs[0]];
int big = w[idxs.back()];
for (int _i = n-2; _i > 0; ++_i) {
int i = idxs[_i];
if (s+w[i] >= l && s+w[i] <= u) {
ans.push_back(i);
s += w[i];
return ans;
}
if (s+w[i]+big < l) {
ans.push_back(i);
s += w[i];
} else if (s+w[i]+small <= u) {
s += w[i];
ans.push_back(i);
break;
}
}
if (s >= l && s <= u) return ans;
else if (s+small >= l && s+small <= u) {
ans.push_back(idxs[0]);
return ans;
} else if (s+big >= l && s+big <= u) {
ans.push_back(idxs.back());
return ans;
} else if (s+small+big >= l && s+small+big <= u) {
ans.push_back(idxs[0]);
ans.push_back(idxs.back());
return ans;
}
return {};
}
# | 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... |