이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int ans = 0;
vector<int64_t>pref(R + 1,0),dpref(R + 1,0);
for (int i = 0 ;i<R - 1;++i){
pref[i + 1] = pref[i] + (X[i + 1] - X[i]);
dpref[i + 2] = pref[i + 1] + dpref[i + 1];
}
auto dist = [&](int l,int r){
return pref[r] * (r - l) - dpref[r] + dpref[l];
};
for (int i = 0;i<R;++i){
int l = 0;
int left = 0,right = i;
while(left<=right){
int mid = (left + right)>>1;
if (dist(mid,i)<=B){
l = mid;
right = mid - 1;
}
else left = mid + 1;
}
int counts = i - l + 1;
int j = i + 1;
ans = max(ans,counts);
while(j<R && l<=i){
if (dist(l,i) + dist(i,j)<=B){
counts++;
++j;
}
else if (l == i){
break;
}
else{
counts--;
++l;
}
ans = max(ans,counts);
}
}
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... |