#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 20;
int a[maxN];
long long pref[maxN];
int besthub(int N, int L, int X[], long long B) {
for (int i = 1; i <= N; i++) {
a[i] = X[i - 1];
pref[i] = pref[i - 1] + a[i];
}
sort(a + 1, a + N + 1);
int res = 0;
for (int i = 1; i <= N; i++) {
int lt = 0;
int rt = L;
while (lt <= rt) {
int mt = (lt + rt) / 2;
int li = lower_bound(a + 1, a + N + 1, a[i] - mt) - a;
int ri = upper_bound(a + 1, a + N + 1, a[i] + mt) - a - 1;
long long cost_l = 1LL * a[i] * (i - li) - (pref[i - 1] - pref[li - 1]);
long long cost_r = (pref[ri] - pref[i]) - 1LL * a[i] * (ri - i);
if (cost_l + cost_r <= B) {
res = max(res, ri - li + 1);
lt = mt + 1;
}
else {
rt = mt - 1;
}
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
612 KB |
Output is correct |
2 |
Correct |
30 ms |
596 KB |
Output is correct |
3 |
Correct |
105 ms |
1852 KB |
Output is correct |
4 |
Correct |
166 ms |
1852 KB |
Output is correct |
5 |
Incorrect |
37 ms |
1024 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |