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 p[200000], bound;
int hub;
bool check(int x, int X[])
{
int m = (x-1) / 2;
if((x % 2) && (p[x-1] - p[m] - p[m-1] <= bound))
return true;
else if((x % 2 == 0) && (p[x-1] - p[m] - p[m-1] - X[m] <= bound))
return true;
for(int i = 1; i <= hub - x; i++)
{
int m = i + (x-1)/2;
if((x % 2) && (p[i+x-1] - p[m] - (p[m-1] - p[i-1]) <= bound))
return true;
else if((x % 2 == 0) && (p[i+x-1] - p[m] - (p[m-1] - p[i-1]) - X[m] <= bound))
return true;
}
return false;
}
int search(int lo, int hi, int X[])
{
int m = (lo + hi)/2;
if(lo == hi)
return lo;
if(hi == lo + 1)
m = hi;
if(check(m,X))
return search(m,hi,X);
else
return search(lo,m-1,X);
}
int besthub(int R, int L, int X[], long long B)
{
bound = B;
hub = R;
p[0] = X[0];
for(int i = 1; i < R; i++)
p[i] = p[i-1] + X[i];
return search(1,R,X);
}
# | 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... |