제출 #1263062

#제출 시각아이디문제언어결과실행 시간메모리
1263062sohamsen15쌀 창고 (IOI11_ricehub)C++20
17 / 100
0 ms328 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; using ll = long long; int besthub(int n, int maxCoordinate, int aArr[], ll budget) { vector<ll> a(n + 1); for (ll i = 1; i <= n; i++) a[i] = aArr[i - 1]; vector<ll> p(n + 1); p[0] = 0; for (ll i = 1; i <= n; i++) p[i] = a[i] + p[i - 1]; int ans = 0; for (int l = 1; l <= n; l++) { int low = l, high = n; function<bool(int)> possible = [&](int r) { ll m = l + (r - l) / 2; ll cost = a[m] * (2 * m + 1 - l - r) + (p[r] + p[l - 1] - 2 * p[m]); return cost <= budget; }; while (low <= high) { int mid = (low + high) / 2; if (possible(mid)) { ans = max(ans, mid - l + 1); if (mid == low) break; else if (mid == high) break; else if (!possible(mid + 1)) break; else low = mid + 1; } else high = mid - 1; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...