Submission #981047

#TimeUsernameProblemLanguageResultExecution timeMemory
981047kilkuwuRice Hub (IOI11_ricehub)C++17
100 / 100
9 ms4508 KiB
#include "ricehub.h" #include <bits/stdc++.h> int besthub(int R, int L, int X[], long long B) { std::vector<int64_t> pref(R + 1); for (int i = 0; i < R; i++) { pref[i + 1] = pref[i] + X[i]; } auto check = [&](int mid) -> bool { // 3 / 2 = 1 // 4 / 2 = 2 // 0 1 2 3 int elem = mid / 2; int num_left = elem; int num_right = mid - num_left; for (int i = 0; i + mid <= R; i++) { int64_t me = X[i + elem]; auto sum_left = pref[i + elem] - pref[i]; // i -> auto sum_right = pref[i + mid] - pref[i + elem]; auto ans = me * num_left - sum_left + sum_right - me * num_right; if (ans <= B) return true; } return false; }; int ans = 0; int lb = 1, rb = R; while (lb <= rb) { int mb = (lb + rb) / 2; if (check(mb)) { ans = mb; lb = mb + 1; } else { rb = mb - 1; } } return ans; } #ifdef LOCAL #include "ricehub.h" #include <stdio.h> #include <stdlib.h> #define MAX_R 1000000 static int R, L; static long long B; static int X[MAX_R]; static int solution; inline void my_assert(int e) {if (!e) abort();} static void read_input() { int i; my_assert(3==scanf("%d %d %lld",&R,&L,&B)); for(i=0; i<R; i++) my_assert(1==scanf("%d",&X[i])); my_assert(1==scanf("%d",&solution)); } int main() { int ans; read_input(); ans = besthub(R,L,X,B); if(ans==solution) printf("Correct.\n"); else printf("Incorrect. Returned %d instead of %d.\n",ans,solution); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...