제출 #1128371

#제출 시각아이디문제언어결과실행 시간메모리
1128371lucaskojima쌀 창고 (IOI11_ricehub)C++17
100 / 100
12 ms2376 KiB
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; using ll = long long; int besthub(int n, int x, int vv[], ll c) { vector<ll> v(n + 1); for (int i = 1; i <= n; i++) v[i] = vv[i - 1]; vector<ll> pref(n + 1); for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + v[i]; auto ok = [&](int k) -> bool { for (int l = 1, r = k; r <= n; l++, r++) { int m = (l + r) / 2; ll sumL = pref[m - 1] - pref[l - 1]; ll sumR = pref[r] - pref[m]; ll cost = abs(v[m] * (m - l) - sumL) + abs(sumR - v[m] * (r - m)); if (cost <= c) return true; } return false; }; int l = 1; // l is good int r = n + 1; // r is bad while (r > l + 1) { int m = (l + r) / 2; ok(m) ? l = m : r = m; } 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...