#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 |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |