# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
895791 | 2023-12-30T20:48:40 Z | vjudge1 | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long bool check(int mid, vector<ll>& psum, vector<int>& x, int money){ for(int i = mid; i < psum.size(); i++){ ll val = x[i - mid/2]; val *= (mid - mid/2); ll tot = val - (psum[i - mid/2] - psum[i - mid]); tot += (psum[i] - psum[i - mid/2]) - (x[i-mid/2] * (mid/2)); if(tot <= money){ return true; } } return false; } int besthub(int r, int l, vector<int> x, int b){ vector<ll> psum(r+1); psum[0] = 0; for(int i = 1; i <= r; i++){ psum[i] = psum[i-1] + x[i-1]; } int left = 0, right = r, mid; while(left < right){ mid = (left + right + 1)/2; if(check(mid, psum, x, b)){ left = mid; }else{ right = mid-1; } } return left; } // signed main(){ // ios_base::sync_with_stdio(0); cin.tie(0); // vector<int> v; // v.push_back(1); v.push_back(2); v.push_back(10); v.push_back(12); v.push_back(14); // cout << besthub(5, 20, v, 6); // }