Submission #29505

#TimeUsernameProblemLanguageResultExecution timeMemory
29505inqrRice Hub (IOI11_ricehub)C++14
58 / 100
46 ms6708 KiB
#include "ricehub.h" #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define rt insert #define st first #define nd second #define ll long long using namespace std; vector < ll > presum; ll fienum; int ans; ll b; ll sum(ll l,ll r){ if(l==0)return presum[r]; else return presum[r]-presum[l-1]; } ll comp(ll l,ll r,int X[]){ ll m=(l+r)/2; ll lc=m-l,rc=r-m; return lc*X[m]-sum(l,m-1)+sum(m+1,r)-rc*X[m]; } void solve(ll s,int X[]){ ll l=s,r=fienum-1; while(l<=r){ ll m=(l+r)/2; //printf("s=%d l=%d r=%d m=%d comp=%d %d\n",s,l,r,m,comp(s,m,X).st,comp(s,m,X).nd); if(comp(s,m,X)<=b){ l=m+1; ans = (m-s+1>ans) ? m-s+1 : ans; } else r=m-1; } } int besthub(int R, int L, int X[], ll B) { fienum=R;b=B; presum.resize(R); presum[0]=X[0]; for(int i=1;i<R;i++)presum[i]=presum[i-1]+X[i]; for(int i=0;i<R;i++){ solve(i,X); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...