#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int x[], long long B)
{
vector<long long> pref(R+1,0);
for(int i = 0;i<R;i++){
pref[i+1] = pref[i]+x[i];
}
int ans = 0;
for(int i = 0;i<R;i++){
int l = 0;
int r = R+1;
int j = 0;
while(l+1<r){
j = (l+r)/2;
int mid = (i+j) >> 1;
long long cost = (long long)(mid-i)*x[mid]*1LL-(pref[mid]-pref[i]); // Seg unten
cost += (long long)(pref[j+1]-pref[mid+1])-(j-mid)*x[mid]*1LL; // seg oben
if(cost <= B) {
ans = max(ans,j-i+1);
l = j;
}else r = j;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
468 KB |
Output is correct |
3 |
Incorrect |
22 ms |
1492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |