#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 && here + used >= ans){
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 |
1 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 |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 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 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 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 |
10 ms |
460 KB |
Output is correct |
2 |
Correct |
10 ms |
460 KB |
Output is correct |
3 |
Correct |
10 ms |
1484 KB |
Output is correct |
4 |
Correct |
105 ms |
1484 KB |
Output is correct |
5 |
Correct |
28 ms |
844 KB |
Output is correct |
6 |
Correct |
28 ms |
844 KB |
Output is correct |
7 |
Correct |
10 ms |
1488 KB |
Output is correct |
8 |
Correct |
89 ms |
1444 KB |
Output is correct |
9 |
Correct |
44 ms |
844 KB |
Output is correct |
10 |
Correct |
43 ms |
848 KB |
Output is correct |
11 |
Correct |
11 ms |
1484 KB |
Output is correct |
12 |
Correct |
109 ms |
1440 KB |
Output is correct |
13 |
Incorrect |
32 ms |
784 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |