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 "ricehub.h"
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;
int besthub(int n, int , int X[], ll b)
{
vector<ll> x(n);
for (int i = 0; i < n; ++i) x[i] = X[i];
sort(x.begin(), x.end());
vector<ll> pref(n);
partial_sum(x.begin(), x.end(), pref.begin());
int maxRes = 0;
for (int i = 0; i < n; ++i)
{
int l = 0, r = n - i;
while (l < r)
{
int m = (l + r) >> 1;
int e = i + m;
int v = (i + e) >> 1;
ll sum = pref[e] - pref[v];
if (v != 0) sum -= pref[v - 1] - (i == 0 ? 0ll : pref[i - 1]);
if (i % 2 != e % 2) sum -= x[v];
if (sum <= b) l = m + 1;
else r = m;
}
maxRes = max(maxRes, l);
}
return maxRes;
}
# | 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... |