Submission #1012682

#TimeUsernameProblemLanguageResultExecution timeMemory
1012682LucaLucaMRice Hub (IOI11_ricehub)C++17
100 / 100
13 ms2652 KiB
#include <iostream> #include "ricehub.h" typedef long long ll; int besthub(int n, int l, int a[], long long b) { int answer = 0; ll sum[n + 1] = {}; for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1] + a[i - 1]; } auto cost = [&](int l, int r) { int mid = (l + r) / 2; return sum[r] - sum[mid] - (ll) (r - mid) * a[mid - 1] + (ll) (mid - l + 1) * a[mid - 1] - (sum[mid] - sum[l - 1]); }; for (int i = 1, j = 1; i <= n; i++) { while (j <= n && cost(i, j) <= b) { j++; } answer = std::max(answer, j - i); } return answer; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...