#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int low = 0;
int high = R*2;
while(low < high){
int mid = (high+low)/2;
// cout << mid << " " << low << " " << high << endl;
long long sum = 0;
long long now = X[mid/2];
long long pluss = mid - mid/2 - 1;
long long mines = mid - pluss + 1;
for (int i = 0 ; i < mid ; i++){
sum+= llabs(now - X[i]);
}
if (sum <= B){
low = mid + 1;
continue;
}
int good = false;
for (int i = now + 1 ; i + pluss < R ; i++){
int bye = X[i - mines];
sum-= llabs(X[i-1] - bye);
int hello = X[i + pluss];
sum+= llabs(X[i] - hello);
sum+= llabs(X[i] - X[i-1])*mines;
sum-= llabs(X[i] - X[i-1])*(pluss - 1);
if (sum <= B){
low = mid + 1;
good = true;
break;
}
}
if (good)continue;
high = mid - 1;
}
return low - 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Incorrect |
21 ms |
1792 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |