#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll cum[100000];
ll sum(int a,int b){
if(a>b)return 0;
return cum[b]-(a?cum[a-1]:0);
}
int besthub(int R, int L, int X[], long long B)
{
for (int i = 0; i < R; ++i)
{
cum[i]=X[i];
if(i)cum[i]+=cum[i-1];
}
int ans=1;
for (int i = 0; i < R; ++i)
for (int j = i+ans; j < R; ++j)
{
int idx=i+(j-i)/2;
ll nb_a=idx-i,nb_b=j-idx;
ll cost=nb_a*X[idx]-sum(i,idx-1)+sum(idx+1,j)-nb_b*X[idx];
if(cost<=B)ans=max(ans,j-i+1);
else break;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 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 |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 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 |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
18 ms |
1528 KB |
Output is correct |
4 |
Correct |
18 ms |
1536 KB |
Output is correct |
5 |
Correct |
9 ms |
896 KB |
Output is correct |
6 |
Correct |
8 ms |
896 KB |
Output is correct |
7 |
Correct |
16 ms |
1536 KB |
Output is correct |
8 |
Correct |
16 ms |
1536 KB |
Output is correct |
9 |
Correct |
7 ms |
896 KB |
Output is correct |
10 |
Correct |
7 ms |
896 KB |
Output is correct |
11 |
Correct |
20 ms |
1536 KB |
Output is correct |
12 |
Correct |
23 ms |
1528 KB |
Output is correct |
13 |
Correct |
8 ms |
916 KB |
Output is correct |
14 |
Correct |
8 ms |
896 KB |
Output is correct |
15 |
Correct |
15 ms |
1152 KB |
Output is correct |
16 |
Correct |
16 ms |
1152 KB |
Output is correct |
17 |
Correct |
17 ms |
1432 KB |
Output is correct |
18 |
Correct |
17 ms |
1408 KB |
Output is correct |
19 |
Correct |
18 ms |
1408 KB |
Output is correct |
20 |
Correct |
18 ms |
1408 KB |
Output is correct |