Submission #1003181

#TimeUsernameProblemLanguageResultExecution timeMemory
1003181vjudge1Rice Hub (IOI11_ricehub)C++17
17 / 100
55 ms3420 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; for(i = 1; i <= n; i++) h[i] = X[i-1]; 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; ll rh = (h[mid] + h[i]) / 2; ll tl = i, tr = mid, ok = i; //cout << "mid: " << mid << " rh: " << rh << " tmid: "; while(tl <= tr) { ll tmid = (tl + tr) / 2; if(h[tmid] > rh) tr = tmid - 1; else{ ok = max(ok, tmid); tl = tmid + 1; } } ll tmid = ok; //cout << tmid << " sum1: "; ll sum1 = rh * (tmid - i + 1) - (pref[tmid] - pref[i-1]); ll sum2 = pref[mid] - pref[tmid] - (mid - tmid) * rh; ll sum = sum1 + sum2; //cout << sum1 << " sum2: " << sum2 << " sum: " << sum << "\n"; if(sum > B) r = mid - 1; else { ans = max(ans, mid); l = 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...