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 <bits/stdc++.h>
using namespace std;
int besthub(int n, int p, int a[], long long k)
{
long long prefix[n];
for (int i=0; i<n; i++)
{
if (i==0)
prefix[i]=a[i];
else
prefix[i]=prefix[i-1]+a[i];
}
long long l=0, r=0, m;
long long maxrice=0;
while (r<n)
{
m=(r+l)/2;
long long distanceright, distanceleft;
distanceright=prefix[r]-prefix[m];
if (l!=0)
distanceleft=prefix[m-1]-prefix[l-1];
else if (m!=0)
distanceleft=prefix[m-1];
else
distanceleft=0;
long long budget=(a[m]*(m-l)-distanceleft)+(distanceright-a[m]*(r-m));
if (budget<=k)
{
maxrice=max(maxrice, r-l+1);
r=r+1;
}
else
{
r=r+1;
l=l+1;
}
}
return maxrice;
}
# | 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... |