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"
using namespace std;
typedef long long ll;
ll get_sum(int l, int r, ll sum[]){
	return (l==0) ? sum[r] : sum[r]-sum[l-1];
}
bool check(int l, int r, ll b, int v[], ll sum[]){
	int med=(l+r)/2;
	ll act=(long long) v[med]*(med-l+1LL)-get_sum(l,med,sum);
	act+=(long long) get_sum(med,r,sum)-v[med]*(r-med+1LL);
	return act<=b;
}
int besthub(int n, int dist, int v[], ll b){
	ll sum[n];
	sum[0]=v[0];
	for(int i=1;i<n;i++)
		sum[i]=sum[i-1]+v[i];
	int res=0;
	for(int i=0;i<n;i++){
		int l=i,r=n-1,act=0;
		while(l<=r){
			int med=(l+r)/2;
			if(check(i,med,b,v,sum)){
				act=med;
				l=med+1;
			}
			else r=med-1;
		}
		res=max(res,act-i+1);
	}
	return res;
}
| # | 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... |