#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int s[N],a[N];
int cost(int i,int l,int r)
{
if(l>r) return 0;
return a[i]*(i-l)-(s[i-1]-s[l-1])+(s[r]-s[i])-a[i]*(r-i);
}
int besthub(int R,int L,int X[],long long B)
{
for(int i=1;i<=R;i++)
{
a[i]=X[i-1];
s[i]=s[i-1]+a[i];
}
int ans=0;
for(int i=1;i<=R;i++)
{
int pos=a[i];
int l=i,r=R,res=-1;
while(l<=r)
{
int mid=(l+r)/2;
int v=mid;
int need=pos-(a[mid]-pos);
int u=upper_bound(a+1,a+R+1,need)-a;
if(cost(i,u,v)<=B)
{
res=mid;
l=mid+1;
}
else r=mid-1;
}
int need=pos-(a[res]-pos);
int u=upper_bound(a+1,a+R+1,need)-a;
int cur=B-cost(i,u,res);
//if(i==4) cout<<i<<' '<<u<<' '<<res<<' '<<cost(i,u,res)<<'\n';
u--;
while(u>=1&&cur-(pos-a[u])>=0)
{
cur=cur-(pos-a[u]);
u--;
}
cout<<i<<' '<<res<<' '<<u<<'\n';
ans=max(ans,res-u);
}
return ans;
}
/*
int main()
{
int R,L,B;
cin>>R>>L>>B;
int pos[R];
for(int i=0;i<R;i++) cin>>pos[i];
cout<<besthub(R,L,pos,B);
}
5 20 6
1
2
10
12
14
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
1024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |