Submission #584672

#TimeUsernameProblemLanguageResultExecution timeMemory
584672sofijavelkovskaRice Hub (IOI11_ricehub)C++14
100 / 100
15 ms1420 KiB
#include <bits/stdc++.h> using namespace std; int besthub(int n, int p, int a[], long long k) { long long prefix[n]; for (int i=0; i<n; i++) { if (i==0) prefix[i]=a[i]; else prefix[i]=prefix[i-1]+a[i]; } long long l=0, r=0, m; long long maxrice=0; while (r<n) { m=(r+l)/2; long long distanceright, distanceleft; distanceright=prefix[r]-prefix[m]; if (l!=0) distanceleft=prefix[m-1]-prefix[l-1]; else if (m!=0) distanceleft=prefix[m-1]; else distanceleft=0; long long budget=(a[m]*(m-l)-distanceleft)+(distanceright-a[m]*(r-m)); if (budget<=k) { maxrice=max(maxrice, r-l+1); r=r+1; } else { r=r+1; l=l+1; } } return maxrice; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...