# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
393687 | 2021-04-24T08:52:12 Z | Karliver | 쌀 창고 (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#include "ricehub.h" #include <bits/stdc++.h> #include <fstream> #define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x) #define all(v) (v).begin(), (v).end() using namespace std; #define forn(i,n) for (int i = 0; i < (n); ++i) using ll = long long; int mod = (ll)1e9 + 7; #define PI acos(-1) typedef pair<int, int> pairs; typedef complex<ll> G; const int INF = 1e9 + 1; const int N = 1e6 + 100; const double eps = 1e-3; int besthub(int R, int L, int X[], ll B) { int l = 0; int r = 0; vector<ll> sm(R + 1, 0); ll cost = 0; forn(i, R)sm[i + 1] = X[i] + sm[i - 1]; auto upd = [&]() { int mid = (l + r) / 2; cost = 0; cost += (mid - l + 1)* 1ll * X[mid]; cost -= sm[mid + 1] - sm[l]; cost -= (r - mid + 1) * X[mid]; cost += sm[r + 1] - sm[mid]; }; int ans = 0; while(l < R) { while(r < R - 1 && cost <= B) { ++r; upd(); } if(cost > B) { r--; upd(); } ckma(ans, r - l + 1); ++l; } return ans; }