이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "ricehub.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll get_sum(int l, int r, vector<ll> &sum){
return (l==0) ? sum[r] : sum[r]-sum[l-1];
}
bool check(int l, int r, ll b, int v[], vector<ll> &sum){
int med=(l+r)>>1;
ll act=(long long) v[med]*(med-l+1LL)-get_sum(l,med,sum);
act+=(long long) get_sum(med,r,sum)-v[med]*(r-med+1LL);
return act<=b;
}
int besthub(int n, int dist, int v[], ll b){
vector<ll> sum(n);
sum[0]=v[0];
for(int i=1;i<n;i++)
sum[i]=sum[i-1]+v[i];
int res=0;
for(int i=0;i<n;i++){
int l=i,r=n-1,act=0;
while(l<=r){
int med=(l+r)>>1;
if(check(i,med,b,v,sum)){
act=med;
l=med+1;
}
else r=med-1;
}
res=max(res,act-i+1);
}
return res;
}
# | 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... |