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"
#include "molecules.h"
using namespace std;
std::vector<int> find_subset(int l, int r, std::vector<int> w) {
int n = (int) w.size();
vector<long long> suf(n);
vector<long long> pref(n);
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) {
a[i].first = w[i];
a[i].second = i;
}
sort(a.begin(), a.end());
pref[0] = a[0].first;
for (int i = 1; i < n; ++i) {
pref[i] += pref[i - 1] + a[i].first;
}
suf.back() = a.back().first;
for (int i = n - 2; i >= 0; --i) {
suf[i] += suf[i + 1] + a[i].first;
}
auto print = [&](int x, int y) {
vector<int> ans;
for (int i = x; i <= y; ++i) {
ans.push_back(a[i].second);
}
return ans;
};
for (int sz = 1; sz <= n; ++sz) {
long long ps = pref[sz - 1];
long long sf = suf[n - sz];
if (ps >= l && ps <= r) {
return print(0, sz - 1);
} else if (sf >= l && sf <= r) {
return print(n - sz, n - 1);
} else if (ps < l && sf > r) {
for (int i = sz - 1; i < n; ++i) {
int rng = pref[i] - (i >= sz ? pref[i - sz] : 0);
if (rng >= l && rng <= r) {
return print(i - sz + 1, i);
}
}
}
}
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... |