Submission #838363

#TimeUsernameProblemLanguageResultExecution timeMemory
838363MohamedAhmed04Rice Hub (IOI11_ricehub)C++14
100 / 100
11 ms2144 KiB
#include <bits/stdc++.h> #include "ricehub.h" using namespace std ; const int MAX = 1e6 + 10 ; int n ; int arr[MAX] ; long long k ; bool check(int m) { int idx = m/2 ; long long suml = 0 , sumr = 0 ; for(int i = 0 ; i < m-1 ; ++i) { if(i < idx) suml += arr[i] ; else sumr += arr[i] ; } long long Min = 4e18 ; for(int i = m-1 ; i < n ; ++i) { sumr += arr[i] ; if(i >= m) suml -= arr[i-m] , sumr -= arr[idx] , suml += arr[idx] , ++idx ; long long sum = 1ll * arr[idx] * (m/2) - suml ; sum += sumr - 1ll * arr[idx] * ((m+1ll) / 2ll) ; Min = min(Min , sum) ; } return (Min <= k) ; } int besthub(int R, int L, int X[], long long B) { n = R , k = B ; for(int i = 0 ; i < n ; ++i) arr[i] = X[i] ; int l = 1 , r = n ; int ans = 1 ; while(l <= r) { int mid = (l + r) >> 1 ; if(check(mid)) ans = mid , l = mid+1 ; else r = mid-1 ; } return ans ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...