Submission #1003202

#TimeUsernameProblemLanguageResultExecution timeMemory
1003202vjudge1Rice Hub (IOI11_ricehub)C++17
0 / 100
97 ms2264 KiB
#include<bits/stdc++.h> #include "ricehub.h" #define ll long long #define ld long double #define vl vector<ll> #define vi vector<int> #define pii pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define f first #define s second #define pb push_back #define p_b pop_back using namespace std; int besthub(int R, int L, int X[], long long B) { ll n = R, i; ll h[n+5], pref[n+5]; pref[0] = 0; vl v; v.pb(0); map<ll, ll>mp; for(i = 1; i <= n; i++){ h[i] = X[i-1]; v.pb(h[i]); mp[h[i]]++; } for(i = 1; i <= n; i++) pref[i] = pref[i-1] + h[i]; ll res = 0; for(i = 1; i <= n; i++) { ll l = i, r = n, ans = i; //cout << "i: " << i << "\n"; while(l <= r) { ll mid = (l + r) / 2; //cout << "mid: " << mid << " ok: "; ll tl = h[i], tr = h[mid], ok = LLONG_MAX; while(tl <= tr) { ll tmid = (tl + tr) / 2; ll lb = lower_bound(all(v), tmid) - v.begin(); ll sum1 = tmid * (lb - i + 1) - (pref[lb] - pref[i-1]); ll sum2 = pref[mid] - pref[lb] - (mid - lb) * tmid; ll sum = sum1 + sum2; ok = min(ok, sum); if(sum1 > sum2) tr = tmid - 1; else tl = tmid + 1; } //cout << ok << "\n"; if(ok <= B){ l = mid + 1; ans = max(ans, mid); } else r = mid - 1; } res = max(res, ans - i + 1); } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...