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;
const int N = 1e5+5;
int a[N], n;
long long b;
bool check(int cnt){
//two pointers?
int l=0, r=cnt-1;
long long suml = 0, sumr = 0;
long long m = a[cnt/2];
for(int i=0; i<cnt/2; i++)suml += m-a[i];
for(int i=cnt/2;i<cnt;i++)sumr += a[i]-m;
bool flag = false;
while(true){
// cout << suml << ' ' << sumr << '\n';
if(b >= suml + sumr)flag = true;
l++, r++;
int median = l + cnt/2;
if(r >= n)break;
suml -= a[median-1]-a[l-1];
suml += (cnt/2)*(a[median]-a[median-1]);
sumr -= (cnt/2)*(a[median]-a[median-1]);
sumr += a[r]-a[median];
}
return flag;
}
int besthub(int R, int L, int X[], long long B){
n = R;
b = B;
for(int i=0;i<n;i++)a[i] = X[i];
int l=0, r=R+1;
// cout << check(3) << '\n';
while(l+1<r){
int mid = (l+r)/2;
if(check(mid)){
l = mid;
}else {
r = mid;
}
}
return l;
}
# | 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... |