Submission #672126

#TimeUsernameProblemLanguageResultExecution timeMemory
672126Hacv16Rice Hub (IOI11_ricehub)C++17
100 / 100
11 ms2388 KiB
#include<bits/stdc++.h> #include "ricehub.h" #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2") using namespace std; typedef long long ll; const int MAX = 2e6 + 15; const ll INF = 5e18 + 15; ll n, x[MAX], px[MAX], L; ll b; ll sum(ll l, ll r){ return px[r] - (l == 0 ? 0LL : px[l - 1]); } bool f(ll s){ for(ll l = 0, r = s - 1; r < n; l++, r++){ ll m = (l + r) >> 1, cost = 0; cost += sum(m + 1, r) - (r - m) * x[m]; cost += (m - l) * x[m] - sum(l, m - 1); if(cost <= b) return true; } return false; } int besthub(int _n, int _L, int _x[], ll _b){ n = _n; L = _L; b = _b; for(int i = 0; i < n; i++) x[i] = _x[i]; for(int i = 1; i < n; i++) px[i] = x[i] + px[i - 1]; ll l = 0, r = MAX, ans = 1; while(l <= r){ //bbin na resposta int m = (l + r) >> 1; if(f(m)) l = m + 1, ans = m; else r = m - 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...