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"
#define ll long long
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<int> ind(n);
for (int i = 0; i < n; i++)
ind[i] = i;
sort(ind.begin(), ind.end(), [&](int x, int y){
return (w[x] < w[y]);
});
vector<int> answer;
vector<ll> suf(n+1);
suf[n] = 0;
for (int i = n-1; i >= 0; i--)
suf[i] = suf[i+1] + w[ind[i]];
ll pref_sum = 0;
for (int i = 0; i < n; i++){
if (pref_sum > u)
break;
if (pref_sum >= l){
for (int h = 0; h < i; h++)
answer.push_back(ind[h]);
return answer;
}
int st = i, en = n-1;
while (st <= en){
int mid = (st+en) >> 1;
ll sum = pref_sum + suf[mid];
if (l <= sum and sum <= u){
for (int h = 0; h < i; h++)
answer.push_back(ind[h]);
for (int h = mid; h < n; h++)
answer.push_back(ind[h]);
return answer;
}
if (sum > u)
st = mid + 1;
else
en = mid - 1;
}
pref_sum += w[ind[i]];
}
return vector<int>{};
}
# | 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... |