#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[] , long long B){
vector<long long> pref(R);
for(int i = 0 ; i < R ; i++){
if(i == 0) pref[i] = (long long) X[i];
else pref[i] = pref[i - 1] + (long long) X[i];
}
int best = 0;
for(int i = 1 ; i < R ; i++){
int l = 0 , r = i;
int ans = 0;
while(l <= r){
int mid = l + (r - l) / 2;
int used = i - mid;
long long sum = (long long) X[i] * used - (pref[i - 1] - (mid > 0 ? pref[mid - 1] : 0));
long long keep = B - sum;
int left = i , right = R - 1;
int here = 0;
while(left <= right){
int middle = left + (right - left) / 2;
int cur = middle - i;
long long s = pref[middle] - pref[i] - (long long) X[i] * cur;
if(s + sum <= B){
here = max(here , cur);
left = middle + 1;
}
else{
right = middle - 1;
}
}
if(keep >= 0){
ans = max(ans , here + used);
r = mid - 1;
}
else{
l = mid + 1;
}
}
best = max(best , ans);
if(best == R - 1) break;
}
return best + 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
460 KB |
Output is correct |
2 |
Correct |
9 ms |
460 KB |
Output is correct |
3 |
Correct |
11 ms |
1484 KB |
Output is correct |
4 |
Correct |
99 ms |
1356 KB |
Output is correct |
5 |
Correct |
29 ms |
1232 KB |
Output is correct |
6 |
Correct |
30 ms |
1232 KB |
Output is correct |
7 |
Correct |
10 ms |
2256 KB |
Output is correct |
8 |
Correct |
86 ms |
2256 KB |
Output is correct |
9 |
Correct |
40 ms |
1104 KB |
Output is correct |
10 |
Correct |
39 ms |
1104 KB |
Output is correct |
11 |
Correct |
11 ms |
2480 KB |
Output is correct |
12 |
Correct |
99 ms |
2512 KB |
Output is correct |
13 |
Incorrect |
31 ms |
1232 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |