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 <algorithm>
using namespace std;
std::vector<int> find_subset(int L, int U, std::vector<int> W) {
int N = W.size();
vector<pair<long long, int> > V(N);
for (int i = 0; i < N; i++) V[i] = { W[i], i };
sort(V.begin(), V.end());
vector<long long> Left(N + 1), Right(N + 1);
Left[0] = 0;
for (int i = 0; i < N; i++) Left[i + 1] = Left[i] + V[i].first;
Right[N] = 0;
for (int i = N - 1; i >= 0; i--) Right[i] = Right[i + 1] + V[i].first;
reverse(Right.begin(), Right.end());
for (int i = 0; i <= N; i++) {
long long X = L - Left[i];
int Y = lower_bound(Right.begin(), Right.end(), X) - Right.begin();
if (i + Y > N) continue;
if (Left[i] + Right[Y] <= U) {
vector<int> ANS;
for (int j = 0; j < i; j++) ANS.push_back(V[j].second);
for (int j = 0; j < Y; j++) ANS.push_back(V[N - 1 - j].second);
sort(ANS.begin(), ANS.end());
return ANS;
}
}
return { 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... |