Submission #744029

#TimeUsernameProblemLanguageResultExecution timeMemory
744029Sainen420Rice Hub (IOI11_ricehub)C++17
68 / 100
11 ms2516 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; using pi = pair<int,int>; long long int qs[100005]={}; int ans=0; int besthub(int R, int L, int X[], long long B) { for(int i=1;i<=R;i++){ qs[i]=qs[i-1]+X[i-1]; } int l=1,r=R; long long cost; while(l<=r){ int len=(r+l)>>1; bool v =false; //iterate start points //S=i,E=i+len-1,N=(s+e)/2 int S,E,N; //cout << len << '='; for(int i=1;i<=(R-len+1);i++){ S=i,E=i+len-1,N=(S+E+1)/2; cost = (X[N-1]*(N-1-S)) - qs[N-1] + qs[S-1] + qs[E] - qs[N] - ((E-N-1)*X[N-1]); //cout << cost << ' '; if(cost<=B){ v=true; break; } } //cout << endl; if(v){ ans=max(len,ans); l=len+1; }else{ r=len-1; } } 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...