Submission #716594

#TimeUsernameProblemLanguageResultExecution timeMemory
716594Jarif_RahmanRice Hub (IOI11_ricehub)C++17
100 / 100
18 ms2336 KiB
#include "ricehub.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int besthub(int n, int L, int X[], long long B){ vector<ll> pref(n, 0); for(int i = 0; i < n; i++){ if(i) pref[i] = pref[i-1]; pref[i]+=X[i]; } auto sum = [&](int l, int r){ return pref[r]-(l?pref[l-1]:0); }; int ans = 1; for(int i = 0; i < n; i++){ int c = min(i, n-i-1); int a = 1, b = c; if(c == 0){ if(i+1 < n && X[i+1]-X[i] <= B) ans = max(ans, 2); continue; } while(a < b){ int md = (a+b+1)/2; if(sum(i+1, i+md)-sum(i-md, i-1) <= B) a = md; else b = md-1; } if(sum(i+1, i+a)-sum(i-a, i-1) <= B) ans = max(ans, 2*a+1); else a = 0; if(i+a+1 < n && sum(i+1, i+a+1)-sum(i-a, i-1)-X[i] <= B) ans = max(ans, 2*a+2); } 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...