#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int a[maxn];
#ifndef LOCAL
#define cerr if(0)cout
#endif // LOCAL
bool Chk(int X[] , int R , ll B , int ask){
int l = 0 , h = ask - 1;
ll sum = 0;
ll suml = 0;
for(int i = 0 ; i < ask ; ++i){
sum += X[i];
if(i <= (l + h) / 2)suml += X[i];
}
while(true){
cerr << ask << " " << sum << " " << suml << endl;
if((ask % 2) * (ll)X[(l + h) / 2] + sum - 2 * suml <= B)return 1;
if(h == R - 1)break;
sum += -X[l] + X[h + 1];
suml += -X[l] + X[(l + h) / 2 + 1];
++l;++h;
}
return 0;
}
int besthub(int R, int L, int X[], long long B)
{
int l = 1;
int h = R;
while(l <= h){
ll mid = l + h >> 1;
if(Chk(X , R , B , mid))l = mid + 1;
else h = mid - 1;
}
// cerr << Chk(X,R,B,4);
return h;
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:35:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll mid = l + h >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 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 |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 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 |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
256 KB |
Output is correct |
16 |
Correct |
3 ms |
256 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
432 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 |
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 |
408 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
7 ms |
384 KB |
Output is correct |
20 |
Correct |
3 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 |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
17 ms |
692 KB |
Output is correct |
4 |
Correct |
22 ms |
1784 KB |
Output is correct |
5 |
Correct |
14 ms |
912 KB |
Output is correct |
6 |
Correct |
11 ms |
896 KB |
Output is correct |
7 |
Correct |
14 ms |
1536 KB |
Output is correct |
8 |
Correct |
15 ms |
1536 KB |
Output is correct |
9 |
Correct |
9 ms |
768 KB |
Output is correct |
10 |
Correct |
9 ms |
768 KB |
Output is correct |
11 |
Correct |
19 ms |
1792 KB |
Output is correct |
12 |
Correct |
33 ms |
1792 KB |
Output is correct |
13 |
Correct |
13 ms |
896 KB |
Output is correct |
14 |
Correct |
17 ms |
888 KB |
Output is correct |
15 |
Correct |
17 ms |
1408 KB |
Output is correct |
16 |
Correct |
20 ms |
1408 KB |
Output is correct |
17 |
Correct |
23 ms |
1664 KB |
Output is correct |
18 |
Correct |
19 ms |
1664 KB |
Output is correct |
19 |
Correct |
27 ms |
1664 KB |
Output is correct |
20 |
Correct |
21 ms |
1664 KB |
Output is correct |