Submission #468857

#TimeUsernameProblemLanguageResultExecution timeMemory
468857pere_gilRice Hub (IOI11_ricehub)C++14
100 / 100
25 ms1480 KiB
#include "ricehub.h" #include "bits/stdc++.h" using namespace std; typedef long long ll; ll get_sum(int l, int r, ll sum[]){ return (l==0) ? sum[r] : sum[r]-sum[l-1]; } bool check(int l, int r, ll b, int v[], 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){ 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...