/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin (),v.end()
using namespace std;
int n,ans;
LL x[100005],pr[100005],s;
LL cost(int l,int r)
{
int m=(l+r)/2;
LL res=0;
res+=(pr[r]-pr[m])-((LL)(r-m)*x[m]);
l--;
res+=((LL)(m-l)*x[m])-(pr[m]-pr[l]);
//cout<<l<<" : "<<r<<" = "<<res<<endl;
return res;
}
bool check(LL k)
{
int l,r;
l=1;
r=k;
while(r<=n)
{
if(cost(l,r)<=s)
return 1;
l++;
r++;
}
return 0;
}
int besthub(int N,int L,int X[],LL B)
{
n=N;
s=B;
for(int i=1;i<=n;i++)
x[i]=X[i-1]-X[0]+1;
for(int i=1;i<=n;i++)
pr[i]=pr[i-1]+x[i];
int l,r,m;
l=1;
r=n;
cost(1,n);
while(l<=r)
{
m=(l+r)/2;
if(check(m))
{
l=m+1;
ans=m;
}
else
r=m-1;
}
return ans;
}
#ifdef death
int main()
{
int N,L,X[102];
LL B;
cin>>N>>L>>B;
for(int i=0;i<N;i++)
cin>>X[i];
cout<<besthub(N,L,X,B)<<endl;;
return 0;
}
#endif
/*
2
4 5
1 2
4+5+1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
360 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
380 KB |
Output is correct |
28 |
Correct |
2 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
404 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
408 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
888 KB |
Output is correct |
2 |
Correct |
6 ms |
924 KB |
Output is correct |
3 |
Correct |
18 ms |
3320 KB |
Output is correct |
4 |
Correct |
18 ms |
3320 KB |
Output is correct |
5 |
Correct |
11 ms |
1656 KB |
Output is correct |
6 |
Correct |
11 ms |
1660 KB |
Output is correct |
7 |
Correct |
16 ms |
3036 KB |
Output is correct |
8 |
Correct |
16 ms |
3064 KB |
Output is correct |
9 |
Correct |
11 ms |
1528 KB |
Output is correct |
10 |
Correct |
11 ms |
1528 KB |
Output is correct |
11 |
Correct |
20 ms |
3448 KB |
Output is correct |
12 |
Correct |
20 ms |
3320 KB |
Output is correct |
13 |
Correct |
12 ms |
1528 KB |
Output is correct |
14 |
Correct |
11 ms |
1656 KB |
Output is correct |
15 |
Correct |
17 ms |
2552 KB |
Output is correct |
16 |
Correct |
16 ms |
2552 KB |
Output is correct |
17 |
Correct |
18 ms |
2936 KB |
Output is correct |
18 |
Correct |
18 ms |
2936 KB |
Output is correct |
19 |
Correct |
19 ms |
3192 KB |
Output is correct |
20 |
Correct |
19 ms |
3216 KB |
Output is correct |