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>
#include "ricehub.h"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
long long prefix[100001];
prefix[0] = X[0];
for (int i=1; i<R; i++)
{
prefix[i] = prefix[i-1] + (long long)(X[i]);
}
long long cost = 0;
int leng = 0;
int l = 0, r = 0;
while (r < R)
{
int med = (l+r)/2;
cost = 0;
if (med != 0)
{
cost += ((long long)X[med])*((long long)(med-l))-prefix[med-1];
}
cost += prefix[r] - prefix[med] - ((long long)(r-med))*((long long)X[med]);
if (cost <= B)
{
leng = max(leng, r - l + 1);
r++;
}
else
{
l++;
r++;
}
}
return leng;
}
# | 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... |