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;
const int Nmax = 1e5 + 5;
ll x[Nmax], s[Nmax], lim;
int n;
bool check(int nr)
{
int i, m;
ll curr;
for(i=0; i<=n-nr; ++i)
{
m = (i + i + nr - 1) / 2;
curr = (m - i + 1) * x[m] - (s[m] - s[i-1]);
curr += (s[i+nr-1] - s[m]) - (i+nr-1 - m) * x[m];
if(curr <= lim) return 1;
}
return 0;
}
int besthub(int R, int L, int X[], ll B)
{
int st = 0, dr = R, mid, i;
n = R; lim = B;
for(i=0; i<n; ++i) x[i] = X[i], s[i] = s[i-1] + x[i];
while(st <= dr)
{
mid = (st + dr) / 2;
if(check(mid)) st = mid+1;
else dr = mid-1;
}
return dr;
}
# | 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... |