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>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
using ll = int;
ll n, m, q, k, x, y, a, b, c;
vector<int> gen(ll x, vector< pair<ll, ll> > &v, ll l, ll u) {
vector<int> st;
vector<int> ans;
ll num = 0;
ll e = n - 1;
for (int i = x - 1; i >= 0; i--) {
st.push_back(i);
num += v[i].first;
}
while (num < l) {
ll x = st[st.size() - 1];
if (num - v[x].first + v[e].first <= u) {
num -= v[x].first;
num += v[e].first;
ans.push_back(v[e].second);
st.pop_back();
e--;
}
else {
num -= v[x].first;
num += v[x + 1].first;
st[st.size() - 1]++;
}
}
for (auto i : st) {
ans.push_back(v[i].second);
}
return ans;
}
vector<int> find_subset(int l, int u, vector<int> w) {
n = w.size();
vector<int> ans;
vector< pair<ll, ll> > v;
ll sum = 0;
for (int i = 0; i < n; i++) {
if (w[i] >= l && w[i] <= u) {
ans.push_back(i);
return ans;
}
v.push_back({w[i], i});
sum += w[i];
}
sort(v.begin(), v.end());
ll mn = 0, mx = 0;
for (int i = 0; i < n; i++) {
mn += v[i].first;
mx += v[n - 1 - i].first;
// cout << mn << ' ' << mx << '\n';
if (min(mx, (ll)u) >= max(mn, (ll)l)) {
return gen(i + 1, v, l, u);
}
}
return ans;
}
# | 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... |