#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
long long N,len,cost,A[100005],S[100005];
bool check(long long x) {
long long idx=(x+1)/2;
for (int i=idx; i+x/2<=N; i++)
if (cost>=((x-1)/2)*A[i]-(S[i-1]-S[i-1-(x-1)/2])+(S[i+x/2]-S[i])-(x-(x-1)/2-1)*A[i]) return 1;
return 0;
}
int besthub(int n, int L, int X[], long long B){
N=n,len=L,cost=B;
for (int i=0; i<N; i++) {
A[i+1]=X[i];
S[i+1]=S[i]+A[i+1];
}
int l=1,r=N,mid,res;
while (l<=r) {
mid=(l+r)/2;
if (check(mid)) { res=mid; l=mid+1; }
else r=mid-1;
}
return res;
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:27:12: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
return res;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
528 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 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 |
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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
424 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 |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 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 |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
380 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 |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 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 |
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 |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 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 |
412 KB |
Output is correct |
27 |
Correct |
3 ms |
508 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
872 KB |
Output is correct |
2 |
Correct |
5 ms |
888 KB |
Output is correct |
3 |
Correct |
19 ms |
3320 KB |
Output is correct |
4 |
Correct |
19 ms |
3320 KB |
Output is correct |
5 |
Correct |
10 ms |
1656 KB |
Output is correct |
6 |
Correct |
10 ms |
1656 KB |
Output is correct |
7 |
Correct |
16 ms |
3064 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
9 ms |
1528 KB |
Output is correct |
10 |
Correct |
10 ms |
1528 KB |
Output is correct |
11 |
Correct |
21 ms |
3264 KB |
Output is correct |
12 |
Correct |
21 ms |
3364 KB |
Output is correct |
13 |
Correct |
11 ms |
1656 KB |
Output is correct |
14 |
Correct |
11 ms |
1660 KB |
Output is correct |
15 |
Correct |
16 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 |
19 ms |
3036 KB |
Output is correct |
19 |
Correct |
21 ms |
3192 KB |
Output is correct |
20 |
Correct |
21 ms |
3192 KB |
Output is correct |