This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ricehub.h>
using namespace std;
const long long INFll = 1e18;
const int INFii = 1e9;
const long long mod = (long long) 1e9 + 7;
typedef long long ll;
typedef int ii;
typedef double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define maxn 110000
//LEMBRAR DE MUDAR
ll ps[maxn], x[maxn];
int besthub(int R, int L, int X[], long long B){
ps[0] = 0;
for(ll i = R; i >= 1; i--) {
x[i] = X[i-1];
}
for(ll i = 1; i <= R; i++) {
ps[i] = ps[i-1] + x[i];
}
ll ans = 0;
for(ll i = 1; i <= R; i++) {
ll l = i;
ll r = R;
ll mid = (l+r)/2;
ll best = i;
while(l <= r) {
ll m = (i+mid)/2;
ll cost = x[m]*(m-i+1) - ps[m] + ps[i-1] + ps[mid] - ps[m] - x[m]*(mid-m);
if(cost <= B) {
best = mid;
l = mid+1;
mid = (l+r)/2;
}
else {
r = mid-1;
mid = (l+r)/2;
}
}
ans = max(ans, best-i+1LL);
}
return ans;
}
# | 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... |