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;
long long dp[100010];
int besthub(int n, int q, int a[], long long b)
{
for(int i=1;i<=n;i++)
dp[i]=dp[i-1]+a[i-1];
int l=1;
int r=n;
while(l!=r){
int mid=(l+r+1)/2;
long long mini=LLONG_MAX;
if(mid%2==0){
for(int i=1;i<=n-mid+1;i++){
int m=i+mid/2;
mini=min(mini,dp[i+mid-1]-dp[m-1]*2+dp[i-1]);
}
}
if(mid%2==1){
for(int i=1;i<=n-mid+1;i++){
int m=i+mid/2;
mini=min(mini,dp[i+mid-1]-dp[m]-dp[m-1]+dp[i-1]);
}
}
if(mini<=b){
l=mid;
}
else
r=mid-1;
}
return l;
}
# | 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... |