Submission #317135

#TimeUsernameProblemLanguageResultExecution timeMemory
317135nandonathanielRice Hub (IOI11_ricehub)C++14
100 / 100
19 ms1792 KiB
#include "ricehub.h" #include "bits/stdc++.h" using namespace std; int besthub(int R, int L, int X[], long long B) { int ki=1,ka=R,res; while(ki<=ka){ int mid=(ki+ka)/2; long long cost=0; int idx=(mid-1)/2; for(int i=0;i<mid;i++)cost+=abs(X[i]-X[idx]); long long mini=cost; for(int i=mid;i<R;i++){ cost-=abs(X[i-mid]-X[idx]); idx++; int selisih=X[idx]-X[idx-1]; cost-=(1LL*(i-idx)*selisih); cost+=(1LL*(mid-1-i+idx)*selisih); cost+=abs(X[i]-X[idx]); mini=min(mini,cost); } if(mini<=B){ res=mid; ki=mid+1; } else ka=mid-1; } return res; }

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:29:9: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |  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...