Submission #1003393

#TimeUsernameProblemLanguageResultExecution timeMemory
1003393vjudge1Rice Hub (IOI11_ricehub)C++17
100 / 100
17 ms3420 KiB
#pragma GCC optimize("-O3") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #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 pb push_back #define p_b pop_back #define f first #define s second using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int besthub(int R, int L, int X[], long long B) { ll n = R, i, res = 0; ll h[n+5], pref[n+5]; pref[0] = 0; for(i = 1; i <= n; i++) { h[i] = X[i-1]; pref[i] = pref[i-1] + h[i]; } for(i = 1; i <= n; i++) { ll l = i, r = n; while(l <= r) { ll mid = (l + r) / 2; ll idx = (i + mid) / 2; ll sum1 = pref[idx-1] - pref[i-1]; ll sum2 = pref[mid] - pref[idx-1]; ll sum = (h[idx] * (idx - i) - sum1) + (sum2 - (mid - idx + 1) * h[idx]); if(sum <= B) { res = max(res, mid - i + 1); l = mid + 1; } else r = mid - 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...