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>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
return y > x ? (x = y, true) : false;
}
void debug_out() {
cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
cerr << ' ' << A;
debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
for (int i = 0; i < n; ++i) {
cerr << a[i] << ' ';
}
cerr << endl;
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
vector<int> find_subset(int L, int R, vector<int> w) {
int n = w.size();
ll S = accumulate(all(w), 0LL);
if (S < L) return {};
if (S <= R) {
vector<int> ans(n);
iota(all(ans), 0);
return ans;
}
vector<pii> a(n);
for (int i = 0; i < n; ++i) {
a[i] = {w[i], i};
}
sort(all(a));
ll pref = S - a[n - 1].fi;
ll suff = 0;
int j = n;
for (int i = n - 2; i >= -1; --i) {
while (j - 1 > i && suff + pref + a[j - 1].fi <= R) {
suff += a[--j].fi;
}
if (L <= pref + suff && pref + suff <= R) {
vector<int> ans;
for (int l = 0; l <= i; ++l) {
ans.push_back(a[l].se);
}
for (int l = j; l < n; ++l) {
ans.push_back(a[l].se);
}
return ans;
}
if (i >= 0) {
pref -= a[i].fi;
}
}
return {};
}
#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}
#endif
# | 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... |