This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |