#include "ricehub.h"
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
using namespace std;
ll i,n,ans,a[111111],b,c[111111];
bool can(ll k, ll kk){
ll md=(k+kk)/2,cst;
ll md1=(k+kk)/2+1,cst1;
if(k && md)cst=(md-k)*a[md]-c[md-1]+c[k-1]+c[kk]-c[md]-(kk-md)*a[md];
else if(md) cst=(md-k)*a[md]-c[md-1]+c[kk]-c[md]-(kk-md)*a[md];
else cst=c[kk]-c[md]-(kk-md)*a[md];
if(k && md1)cst=(md1-k)*a[md1]-c[md1-1]+c[k-1]+c[kk]-c[md1]-(kk-md1)*a[md1];
else if(md1) cst=(md1-k)*a[md1]-c[md1-1]+c[kk]-c[md1]-(kk-md1)*a[md1];
else cst=c[kk]-c[md1]-(kk-md1)*a[md1];
//cout<<k<<" "<<kk<<" "<<cst<<"\n";
if(cst<=b) return 1;
else return 0;
}
ll fnd(ll k){
ll x=k,y=n-1;
while(x+1<y){
ll mid=(x+y)/2;
if(can(k,mid))x=mid;
else y=mid;
}
return y;
}
int besthub(int R, int L, int X[], long long B) {
n=R;
b=B;
for(i=0;i<n;i++) a[i]=X[i];
c[0]=a[0];
for(i=1;i<n;i++)c[i]=c[i-1]+a[i];
for(i=0;i<R;i++) ans=max(ans,fnd(i)-i+1);
return ans;
}
Compilation message
ricehub.cpp: In function 'bool can(long long int, long long int)':
ricehub.cpp:11:20: warning: unused variable 'cst1' [-Wunused-variable]
ll md1=(k+kk)/2+1,cst1;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |