Submission #165757

#TimeUsernameProblemLanguageResultExecution timeMemory
165757HideoRice Hub (IOI11_ricehub)C++11
100 / 100
22 ms4088 KiB
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include "ricehub.h" //#include "grader.cpp" using namespace std; #define ll long long const int N = 1e5 + 7; ll a[N], pr[N], sf[N]; int n; ll mx; bool solve (int l, int r){ int mid = ((l + r) >> 1) + 1; ll cost = (pr[mid] - pr[l] - (a[mid] - a[l]) * 1LL * (l - 1)) + (sf[mid] - sf[r] - (a[r] - a[mid]) * 1LL * (n - r)); return cost <= mx; } int besthub(int R, int L, int X[], long long B){ n = R; mx = B; for (ll i = 0; i < n; i++){ a[i + 1] = X[i]; pr[i + 1] = pr[i] + i * (a[i + 1] - a[i]); } for (ll i = n; i >= 1; i--) sf[i] = sf[i + 1] + (n - i) * (a[i + 1] - a[i]); int l = 1, r = n + 1; while (r - l > 1){ int mid = (l + r) >> 1; bool ans = false; for (int i = 1; i + mid - 1 <= n; i++) ans |= solve(i, i + mid - 1); if (ans) l = mid; else r = mid; } return l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...