Submission #211556

#TimeUsernameProblemLanguageResultExecution timeMemory
211556biggRice Hub (IOI11_ricehub)C++14
100 / 100
34 ms3456 KiB
#include "ricehub.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 112345; long long int ar[MAXN]; long long sumr[MAXN]; int besthub(int R, int L, int X[], long long B) { //sumr[0] = X[0] for(int i = 1; i <= R; i++){ ar[i] = X[i - 1]; sumr[i] = sumr[i - 1] + ar[i]; } long long int ans = 0; for(int i = 1; i <= R; i++){ long long int l = i, r = R, j; while(r - l >= 0){ long long int mid = (l + r)/2; long long int mid2 = (i + mid)/2; long long cost = ar[mid2] * (mid2 - i + 1) - (sumr[mid2] - sumr[i - 1]) + (sumr[mid] - sumr[mid2]) - ar[mid2] * (mid - mid2); if(cost <= B){ j = mid; l = mid + 1; }else r = mid - 1; } ans = max(ans, j - i + 1); } return (int) ans; } // int r, l, x[MAXN]; // long long b; // int main(){ // scanf("%d %d %lld", &r, &l, &b); // for(int i = 0; i < r; i++){ // scanf("%d", &x[i] ); // } // printf("%d\n", besthub(r, l, x, b)); // }

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:30:20: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ans = max(ans, j - i + 1);
                  ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...