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;
typedef pair <int, int> pii;
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
const int N = 1e5+7;
vector <ll> pref(N), suff(N), v(N);
int n;
ll getpref(int l, int r){
return pref[r]-1ll*(l-1)*(v[r]-v[l-1])-pref[l-1];
}
ll getsuff(int l, int r){
return suff[l]-1ll*(n-r)*(v[r+1]-v[l])-suff[r+1];
}
bool check2(int l, int r, ll B){
int mid = (l+r) >> 1;
return getpref(l, mid)+getsuff(mid, r) <= B;
}
bool check(int x, ll B){
int flag = 0;
for(int i = 1; i+x-1 <= n; i++){
if(check2(i, i+x-1, B)){
flag++;
break;
}
}
return flag;
}
int besthub(int R, int L, int X[], long long B){
n = R;
int i;
for(i = 0; i < R; i++){
v[i+1] = X[i];
}
for(i = 1; i <= n; i++){
pref[i] = pref[i-1]+1ll*(i-1)*(v[i]-v[i-1]);
}
for(i = n; i; i--){
suff[i] = suff[i+1]+1ll*(n-i)*(v[i+1]-v[i]);
}
int l = 1, r = n;
while(l < r){
int mid = (l+r+1) >> 1;
if(check(mid, B)) l = mid;
else r = mid-1;
}
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... |