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>
using namespace std;
#define ll long long
#define f first
#define s second
#define pf push_front
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
/*
int besthub(int n, int last, int x[], ll b){
int ans = 0;
int l , r;
for(int i = 0; i < n; i++){
l = i - (lower_bound(x.begin(), x.end(), max(0LL,x[i]-b))- x.begin());
r = upper_bound(x.begin(), x.end(), min((ll) last, x[i]+b)) - x.begin() - (i+1);
// cout << x[i] << " " <<l << " " << r << endl;
ans = max(l+r+1,ans);
}
return ans;
}
*/
int besthub(int n, int last, int x[], ll b){
ll ans = 0;
ll cnt;
ll pref[n];
pref[0] = 0;
for(int i = 1; i < n; i++){
pref[i] = pref[i-1] + (x[i]-x[i-1]);
}
/*
for(int i : pref){
cout << i << " ";
}
cout << endl;
*/
int l = 0;
int final = 1;
for(int r =0; r < n;r++){
int m = (l+r)/2;
// cout << l <<" "<<r<<" "<<x[m]<<" "<<m<<" d "<<(pref[m]-pref[max(0,l-1)]) <<" " << pref[r]-pref[m]<<endl;
ll val = pref[r] - pref[m] + (pref[m]-pref[max(0,l-1)]);
// cout << val <<" "<<l <<" "<<r<< endl;
if( pref[r] - pref[m] + (pref[m]-pref[max(0,l-1)])<= b){
// cout << l << " " << r << endl;
final = max(final,r-l+1);
}
else{
while( pref[r] - pref[m] + (pref[m]-pref[max(0,l-1)]) > b && l<r){
l++;
}
if( pref[r] - pref[max(0,m-1)] + (pref[m]-pref[max(0,l-1)])<= b){
final = max(final,r-l+1);
}
}
}
return final;
}
Compilation message (stderr)
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:55:12: warning: unused variable 'val' [-Wunused-variable]
55 | ll val = pref[r] - pref[m] + (pref[m]-pref[max(0,l-1)]);
| ^~~
ricehub.cpp:34:8: warning: unused variable 'ans' [-Wunused-variable]
34 | ll ans = 0;
| ^~~
ricehub.cpp:36:8: warning: unused variable 'cnt' [-Wunused-variable]
36 | ll cnt;
| ^~~
# | 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... |