Submission #741142

#TimeUsernameProblemLanguageResultExecution timeMemory
741142LCJLYRice Hub (IOI11_ricehub)C++14
100 / 100
12 ms2264 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; int besthub(int R, int L, int X[], long long B) { int n=R,k=L; long long arr[n+5]; for(int x=0;x<n;x++){ arr[x+1]=X[x]; } long long psum[n+5]; for(int x=1;x<=n;x++){ psum[x]=psum[x-1]+arr[x]; } long long l=1; int ans=0; for(long long x=1;x<=n;x++){ while(l<x){ long long mid=(l+x)/2; long long cost=arr[mid]*(mid-l)-(psum[mid-1]-psum[l-1])+(psum[x]-psum[mid])-arr[mid]*(x-mid); if(cost>B){ l++; } else{ break; } } ans=max(ans,(int)x-(int)l+1); } return ans; }

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:8:10: warning: unused variable 'k' [-Wunused-variable]
    8 |  int n=R,k=L;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...