이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long const inf=1e16;
int const N=1e5+5;
long long pre[N];
int cor[N];
long long bug=0;
bool cost(int l,int r){
// cout<<l<<' '<<r<<" checking for it"<<endl;
int p=(l+r)/2;
// cout<<p<<" hub"<<endl;
long long c=0;
int s1=p-l;
int s2=(r+1)-p;
long long sm1=(cor[p]*s1)-(pre[p]-pre[l]);
long long sm2=(pre[r+1]-pre[p])-(cor[p]*s2);
c=sm1+sm2;
// cout<<c<<endl;
return (c<=bug);
}
int besthub(int R, int L, int X[], long long B){
bug=B;
for (int i = 0; i < R; ++i){
pre[i+1]=pre[i]+X[i];
cor[i]=X[i];
}
int low=1,high=R+1;
while(high-low>1){
int mid=(high+low)/2;
// cout<<mid<<' '<<" mid"<<endl;
bool b=0;
for (int i = 0; (i+mid)-1 < R; ++i)
b|=cost(i,(i+mid)-1);
if(b)
low=mid;
else
high=mid;
}
return low;
}
# | 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... |