#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
long long dp[100010];
int besthub(int n, int q, int a[], long long b)
{
for(int i=1;i<=n;i++)
dp[i]=dp[i-1]+a[i-1];
int l=1;
int r=n;
while(l!=r){
int mid=(l+r+1)/2;
long long mini=LLONG_MAX;
if(mid%2==0){
for(int i=1;i<=n-mid+1;i++){
int m=i+mid/2;
mini=min(mini,dp[i+mid-1]-dp[m-1]*2+dp[i-1]);
}
}
if(mid%2==1){
for(int i=1;i<=n-mid+1;i++){
int m=i+mid/2;
mini=min(mini,dp[i+mid-1]-dp[m]-dp[m-1]+dp[i-1]);
}
}
if(mini<=b){
l=mid;
}
else
r=mid-1;
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
448 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
432 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
9 ms |
2652 KB |
Output is correct |
4 |
Correct |
9 ms |
2620 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
6 |
Correct |
4 ms |
1376 KB |
Output is correct |
7 |
Correct |
7 ms |
2152 KB |
Output is correct |
8 |
Correct |
8 ms |
2228 KB |
Output is correct |
9 |
Correct |
4 ms |
1128 KB |
Output is correct |
10 |
Correct |
4 ms |
1244 KB |
Output is correct |
11 |
Correct |
9 ms |
2664 KB |
Output is correct |
12 |
Correct |
9 ms |
2664 KB |
Output is correct |
13 |
Correct |
5 ms |
1384 KB |
Output is correct |
14 |
Correct |
5 ms |
1384 KB |
Output is correct |
15 |
Correct |
16 ms |
1920 KB |
Output is correct |
16 |
Correct |
9 ms |
1896 KB |
Output is correct |
17 |
Correct |
8 ms |
2372 KB |
Output is correct |
18 |
Correct |
8 ms |
2412 KB |
Output is correct |
19 |
Correct |
8 ms |
2392 KB |
Output is correct |
20 |
Correct |
8 ms |
2396 KB |
Output is correct |