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>
#define ll long long
using namespace std;
vector<ll> pr, x;
ll check(ll l, ll r, ll mid){
ll su = x[mid] * (mid - l + 1) - (pr[mid] - pr[l - 1]);
su += (pr[r] - pr[mid]) - x[mid] * (r - mid);
return su;
}
int besthub(int R, int L, int X[], long long B)
{
pr.assign(R + 1, 0), x.assign(R + 1, 0);
for (int i = 1; i <= R; i++){
x[i] = X[i - 1];
pr[i] = pr[i - 1] + x[i];
}
ll l = 1, r = 1, ans = 0;
while(r <= R){
if ((l + r) % 2 == 1){
int mi1 = (l + r) / 2, mi2 = (l + r) / 2 + 1;
ll va1 = check(l, r, mi1), va2 = check(l, r, mi2);
if (l == 2 && r == 5){
cout<<va1<<" "<<va2;
}
if (va1 > va2){
swap(va1, va2);
}
if (va1 > B){
l++;
}
else if (va1 <= B){
r++;
ans = max(ans, (r - l));
}
}
else{
int mi = (l + r) / 2;
ll va = check(l, r, mi);
if (va > B){
l++;
}
else{
r++;
ans = max(ans, (r - l));
}
}
}
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... |