This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "ricehub.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
using namespace std;
vector < int > presum;
int fienum,ans=0;
long long b;
long long sum(int l,int r){
if(l==0)return presum[r];
else return presum[r]-presum[l-1];
}
pair<int,int> comp(int l,int r,int X[]){
int m=(l+r)/2;
int lc=m-l,rc=r-m;
return make_pair(lc*X[m]-sum(l,m-1)+sum(m+1,r)-rc*X[m],r-l+1);
}
void solve(int s,int X[]){
int l=s,r=fienum-1;
while(l<=r){
int m=(l+r)/2;
//printf("s=%d l=%d r=%d m=%d comp=%d %d\n",s,l,r,m,comp(s,m,X).st,comp(s,m,X).nd);
if(comp(s,m,X).st<b){
l=m+1;
ans=max(ans,comp(s,m,X).nd);
}
else r=m-1;
}
}
int besthub(int R, int L, int X[], long long B)
{
fienum=R;b=B;
presum.resize(R);
presum[0]=X[0];
for(int i=1;i<R;i++)presum[i]=presum[i-1]+X[i];
for(int i=0;i<R;i++){
solve(i,X);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |