Submission #521173

#TimeUsernameProblemLanguageResultExecution timeMemory
521173JomnoiRice Hub (IOI11_ricehub)C++17
0 / 100
18 ms2604 KiB
#include <bits/stdc++.h> #include "ricehub.h" #define DEBUG 0 using namespace std; const int N = 1e5 + 10; int n; long long lim; long long x[N]; bool check(int sz) { int mid = (sz + 1) / 2; long long L = 0, R = 0; for(int i = 1; i < mid; i++) { L += x[mid] - x[i]; } for(int i = mid + 1; i <= sz; i++) { R += x[i] - x[mid]; } if(L + R <= lim) { return true; } int l = 2, r = sz + 1; for(int m = mid + 1; r <= n; m++, l++, r++) { L -= x[m - 1] - x[l - 1]; L += x[m] - x[m - 1]; R -= x[m] - x[m - 1]; R += x[r] - x[m]; if(L + R <= lim) { return true; } } return false; } int besthub(int R, int L, int X[], long long B) { n = R; lim = B; for(int i = 1; i <= R; i++) { x[i] = X[i - 1]; } int l = 1, r = R, pos = -1; while(l <= r) { int mid = (l + r) / 2; if(check(mid) == true) { pos = mid; l = mid + 1; } else { r = mid - 1; } } return pos; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...