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;
long long int pos[100002];
long long int acumulado[100002];
long long int cal(int l, int r, int m){
long long int suma = 0;
if(r > m){
suma+= (acumulado[r] - acumulado[m]) - ((r - m) * pos[m]);
}
if(l < m){
suma+= (acumulado[m - 1] - acumulado[l - 1]) - ((m - l) * pos[m]);
}
return suma;
}
int besthub(int R, int L, int X[], long long B)
{
for(int i = 0; i < R; ++i){
pos[i + 1] = X[i];
acumulado[i + 1] = acumulado[i] + pos[i + 1];
}
int l = 1, r = 1, m = 1, ans = 1, n = R;
while(l < n || r < n){
m = (l + r) / 2;
if(cal(l, r, m) <= B){
ans = max(ans, r - l + 1);
if(r < n){
r++;
}else{
l++;
}
}else{
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... |