#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int besthub(int R, int L, int a[], long long B)
{
long long dp[100001];
dp[0]=0;
for(int i=1;i<R;i++){
dp[i]=dp[i-1]+(ll)a[i]-(ll)a[0];
}
ll l=1,r=R;
while(l!=r){
ll mid=(l+r)>>1,flag=0;
for(ll i=mid-1;i<(ll)R;i++){
ll MID=(i*2+1-mid)>>1;
ll left=i+1-mid;
long long cost=dp[i]-dp[MID]-((i-MID)*((ll)a[MID]-(ll)a[0]))+(((ll)a[MID]-(ll)a[left])*(MID-left+1)-(dp[MID]-dp[left]-(MID-left)*((ll)a[left]-(ll)a[0])));
if(cost<=B){
flag++;
break;
}
}
if(flag==0) r=mid;
else l=mid+1;
}
return max(l-1,(ll)1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Incorrect |
28 ms |
2560 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |