This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
//#include "grader.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
ll pre[MAXN], suf[MAXN];
int ind[MAXN];
vector<int> find_subset(int l, int u, vector<int> w) {
int r = 0, n = w.size();
r = n - 1;
for (int i = 0; i < n; i++) ind[i] = i;
sort(ind, ind + n, [&w](int l, int r) -> bool {
if (w[l] == w[r])
return l < r;
return w[l] < w[r];
});
sort(w.begin(), w.end());
pre[0] = w[0], suf[n - 1] = w[n - 1];
if (l <= w[0] && w[0] <= u)
return {ind[0]};
if (l <= w[n-1] && w[n-1] <= u)
return {ind[n-1]};
vector<int> ans;
for (int i = 1; i < n; i++) {
if (l <= w[i] && w[i] <= u)
return {ind[i]};
pre[i] = pre[i - 1] + (ll) w[i], suf[n - i - 1] = suf[n - i] + (ll) w[n - i - 1];
if (l <= pre[i] && pre[i] <= u) {
for (int j = 0; j <= i; j++)
ans.pb(ind[j]);
return ans;
}
if (l <= suf[n - i - 1] && suf[n - i - 1] <= u) {
for (int j = n - 1; j >= n - i - 1; j--)
ans.pb(ind[j]);
return ans;
}
}
for (int i = n - 2; i >= 0; i--) {
while (r - 1 > i && pre[i] + suf[r] < l) r--;
if (l <= pre[i] + suf[r] && pre[i] + suf[r] <= u) {
for (int j = 0; j <= i; j++)
ans.pb(ind[j]);
for (int j = n - 1; j >= r; j--)
ans.pb(ind[j]);
return ans;
}
}
return {};
}
/*int main()
{
vector<int> ans = solve(10, 20, {15, 17, 16, 18});
for (int i: ans)
printf("%d ", i);
printf("\n");
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... |