#include "bits/stdc++.h"
#include "ricehub.h"
using namespace std;
#define ll long long
int a[100010];
ll qs[100010];
bool price(int st , int ed , ll budget)
{
int mid = (st+ed)>>1;
ll temp = a[mid]*((mid-st)-(ed-mid)) - qs[mid-1] + qs[st-1] + qs[ed] - qs[mid];
//temp+=(qs[ed]-qs[mid-1])-1ll*a[mid]*(ed-mid+1);
if(temp<=budget) return 1;
else return 0;
}
int besthub(int n , int L , int X[] , ll budget)
{
for(int i=1;i<=n;i++)
{
a[i]=X[i-1];
//qs[i]=qs[i-1]+a[i];
}
for(int i=1;i<=n;i++)
{
//a[i]=X[i-1];
qs[i]=qs[i-1]+a[i];
}
int mx=-1;
for(int i=1;i<=n;i++)
{
int st=i;
int ed=n;
while(st<=ed)
{
int mid = (st+ed)>>1;
if(price(i,mid,budget)) st=mid+1;
else ed=mid-1;
}
mx=max(mx,st-i);
}
return mx;
}
// int main()
// {
// int r , lim ,x[100010];
// ll bud;
// cin >> r >> lim >> bud ;
// for(int i=0;i<r;i++)
// {
// cin >>x[i];
// }
// //cin >> bud;
// cout << besthub(r,lim,x,bud);
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
428 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
356 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 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 |
4 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
420 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
768 KB |
Output is correct |
2 |
Correct |
7 ms |
684 KB |
Output is correct |
3 |
Correct |
25 ms |
2908 KB |
Output is correct |
4 |
Correct |
29 ms |
2944 KB |
Output is correct |
5 |
Correct |
12 ms |
1440 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
24 ms |
2688 KB |
Output is correct |
8 |
Correct |
22 ms |
2688 KB |
Output is correct |
9 |
Correct |
17 ms |
1408 KB |
Output is correct |
10 |
Correct |
13 ms |
1416 KB |
Output is correct |
11 |
Correct |
26 ms |
2980 KB |
Output is correct |
12 |
Correct |
27 ms |
3072 KB |
Output is correct |
13 |
Correct |
13 ms |
1472 KB |
Output is correct |
14 |
Correct |
13 ms |
1408 KB |
Output is correct |
15 |
Correct |
18 ms |
2304 KB |
Output is correct |
16 |
Correct |
20 ms |
2304 KB |
Output is correct |
17 |
Correct |
21 ms |
2688 KB |
Output is correct |
18 |
Correct |
23 ms |
2688 KB |
Output is correct |
19 |
Correct |
25 ms |
2816 KB |
Output is correct |
20 |
Correct |
23 ms |
2816 KB |
Output is correct |