Submission #542676

#TimeUsernameProblemLanguageResultExecution timeMemory
542676nekiRice Hub (IOI11_ricehub)C++14
100 / 100
15 ms3340 KiB
#include <bits/stdc++.h> #define ll long long #define loop(i, a, b) for(ll i=a;i<b;++i) #define pool(i, a, b) for(ll i=a-1;i>=b;--i) #define fore(i, a) for(auto&& i:a) #define fi first #define se second #define ps(a) push_back(a) #define pb(a) pop_back(a) #define eb(...) emplace_back(__VA_ARGS__) #define sc scanf #define vc vector #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define llmax LLONG_MAX/2 #define llmin -LLONG_MAX/2 using namespace std; #define par pair<ll, ll> #define ld long double #define mod 998244353 int besthub(int n, int L, int X[], ll B){ vc<ll> x(n+1, 0); loop(i, 0, n) x[i+1]=X[i]; vc<ll> pr=x; loop(i, 1, n+1) pr[i]+=pr[i-1]; function<ll (ll, ll)> query=[&](ll l, ll r){ return pr[r] - pr[l-1]; }; function<ll (ll, ll)> cost=[&](ll l, ll r){ ll mid=(l+r)/2; ll ret=0; if(l<mid) ret+=(mid-l) * x[mid] - query(l, mid-1); if(mid<r) ret+=query(mid+1, r) - (r-mid) * x[mid]; return ret; }; ll r=1, ans=0; loop(l, 1, n+1){ while(r+1<=n and cost(l, r+1)<=(ll)B) ++r; ans=max(ans, r-l+1); } return (int)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...