#include "ricehub.h"
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;
int besthub(int n, int l, 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 != m % 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 |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |