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 "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ins insert
#define pb push_back
// #define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
int besthub(int n, int mxL, int arr[], long long B){
int ans=0;
/*
her i ucun ele j tapaqki :
j<i
j ni goturmesek i+1 right terefden nese ekstra goture bilirik
*/
for(int i=0;i<n;i++){
int j =i;
int l =0;
int r = i-1;
while(l<=r){
int mid = (l+r)/2;
int sum=0;
for(int p=mid;p<i;p++){
sum+=abs(arr[i]-arr[p]); // optimze sonra
}
if(sum>B){
l=mid+1;
continue;
}
int x = i;
int sum2=0;
for(;x<n;x++){
if(sum + sum2 + abs(arr[i]-arr[x]) > B){
break;
}
sum2+=abs(arr[i]-arr[x]);
}
// j ni goturmesek
// cout<<i<<" "<<mid<<endl;
sum-=abs(arr[i]-arr[j]);
int xp = x+1;
int fnd=0;
for(;xp<n;xp++){
if(sum+sum2 - abs(arr[i]-arr[xp])>B){
break;
}
fnd++;
sum2+=abs(arr[i]-arr[xp]);
}
ans=max(ans, (i - (j+1)) + (xp - i));
if(fnd>1){
l=mid+1;
}
else{
r=mid-1;
}
}
}
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... |