이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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+= ((m - l) * pos[m]) - (acumulado[m - 1] - acumulado[l - 1]);
}
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... |