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;
# define LL long long
long long ps[100100];
bool can( int k, LL b, int n, int a[] ) {
int j = k - 1;
for ( int i = 0; j < n; j++ ) {
int x = a[(i + j) / 2], m = (i + j) / 2;
LL sum = ps[m - 1];
if ( i ) {
sum -= ps[i - 1];
}
sum = (m - i) * x - sum;
LL sum1 = ps[j] - ps[m];
sum1 -= x * (j - m);
LL cnt = sum + sum1;
if ( cnt <= b ) {
return 1;
}
i++;
}
return 0;
}
int besthub(int n, int mx, int a[], long long b)
{
for ( int i = 0; i < n; i++ ) {
ps[i] = a[i];
if ( i ) {
ps[i] += ps[i - 1];
}
}
int l = 0, r = n, m, ans = 1;
while ( l <= r ) {
m = (l + r) / 2;
if ( can( m, b, n, a ) ) {
ans = m;
l = m + 1;
}
else {
r = m - 1;
}
}
return ans;
}
# | 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... |