#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
long long s[N];
long long cost(int i,int l,int r)
{
if(l>r) return 0;
return 1ll*a[i]*(i-l)-(s[i-1]-s[l-1])+(s[r]-s[i])-1ll*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;
long long 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 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
10 ms |
384 KB |
Output is correct |
24 |
Correct |
9 ms |
384 KB |
Output is correct |
25 |
Correct |
9 ms |
384 KB |
Output is correct |
26 |
Correct |
12 ms |
384 KB |
Output is correct |
27 |
Correct |
8 ms |
384 KB |
Output is correct |
28 |
Correct |
8 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
640 KB |
Output is correct |
2 |
Correct |
22 ms |
768 KB |
Output is correct |
3 |
Execution timed out |
1086 ms |
2944 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |