#include "ricehub.h"
#include<bits/stdc++.h>
#define fi first
#define se second
//#define int long long
using namespace std;
using db=double;
using ll=int64_t;
using sll=__int128;
using lb=long double;
int besthub(int n, int m, int a[], long long mx){
int ans=0;
for(int i=0; i<n; i++){
int cur=1; int left=i-1; int right=i+1; int rem=mx;
while(left>=0 || right<=n-1){
if(left==-1){
if(abs(a[right]-a[i])>rem)break;
else{
cur++; rem-=abs(a[right]-a[i]); right++; continue;
}
}else if(right==n){
if(abs(a[left]-a[i])>rem)break;
else{
cur++; rem-=abs(a[left]-a[i]); left--; continue;
}
}
if(abs(a[left]-a[i])<abs(a[right]-a[i])){
if(abs(a[left]-a[i])>rem)break;
else{
cur++; rem-=abs(a[left]-a[i]); left--; continue;
}
}else{
if(abs(a[right]-a[i])>rem)break;
else{
cur++; rem-=abs(a[right]-a[i]); right++; continue;
}
}
}
ans=max(ans,cur);
}
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... |