Submission #914773

#TimeUsernameProblemLanguageResultExecution timeMemory
914773DucNguyen2007Rice Hub (IOI11_ricehub)C++14
100 / 100
11 ms3672 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int maxN=1e5+5; ll sum[maxN+1]; int a[maxN+1]; ll get(ll l,ll r) { if(l==0) { return sum[r]; } else return sum[r]-sum[l-1]; } bool check(ll len,int n,ll B,int a[]) { ll l=0,r=len-1; while(r<n) { ll p=(l+r)/2; ll cur=(p-l+1)*a[p]-get(l,p)+get(p,r)-(r-p+1)*a[p]; if(cur<=B) { return true; } l++; r++; } return false; } ll besthub(int n,int L,int a[],ll B) { sum[0]=a[0]; for(int i=1;i<n;i++) { sum[i]=sum[i-1]+a[i]; } ll res,l=1,r=n; while(l<=r) { ll mid=(l+r)/2; if(check(mid,n,B,a)) { res=mid; l=mid+1; } else r=mid-1; } return res; } /*5 20 6 1 2 10 12 14*/

Compilation message (stderr)

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