#include <bits/stdc++.h>
#include "ricehub.h"
#define pb push_back
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
long long int a[MAXN], pref[MAXN];
long long int n;
bool check(long long int x, long long int b){
for(long long int i= 1;i<=n-x+1;i++){
vector<long long int> md;
if(x & 1){
md.pb((i + i +x-1)/2);
} else {
md.pb((i + i +x-1)/2);
md.pb(((i + i +x-1)/2)+1);
}
for(long long int m: md){
long long int sum1 = (long long int)pref[m]-(long long int)pref[i-1];
sum1 *= -1;
sum1 += (long long int)(m-(i-1))*(long long int)a[m];
long long int sum2 = (long long int)pref[i+x-1]-(long long int)pref[m];
sum2 -= (long long int)(i+x-1-m)*(long long int)a[m];
long long int sum = sum1+sum2;
if(sum <= b){
return true;
}
}
}
return false;
}
int besthub(int r, int l, int x[], long long int b) {
n = r;
pref[0] = 0;
for(int i= 1;i<=n;i++){
a[i] = (long long int)x[i-1];
pref[i] = (long long int)pref[i-1] + (long long int)a[i];
}
int lo = 1;
int hi = n;
while(lo <= hi){
int mid = lo+(hi-lo)/2;
if(check((long long int) mid, b)){
lo = mid+1;
} else {
hi = mid-1;
}
}
if(!check(lo, b)){
return hi;
}
return lo;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
756 KB |
Output is correct |
2 |
Correct |
14 ms |
748 KB |
Output is correct |
3 |
Correct |
15 ms |
2284 KB |
Output is correct |
4 |
Correct |
15 ms |
2284 KB |
Output is correct |
5 |
Correct |
32 ms |
1260 KB |
Output is correct |
6 |
Correct |
35 ms |
1260 KB |
Output is correct |
7 |
Correct |
14 ms |
2284 KB |
Output is correct |
8 |
Correct |
14 ms |
2284 KB |
Output is correct |
9 |
Correct |
30 ms |
1260 KB |
Output is correct |
10 |
Correct |
29 ms |
1260 KB |
Output is correct |
11 |
Correct |
16 ms |
2284 KB |
Output is correct |
12 |
Correct |
16 ms |
2284 KB |
Output is correct |
13 |
Correct |
38 ms |
1260 KB |
Output is correct |
14 |
Correct |
33 ms |
1260 KB |
Output is correct |
15 |
Correct |
12 ms |
1772 KB |
Output is correct |
16 |
Correct |
12 ms |
1772 KB |
Output is correct |
17 |
Correct |
16 ms |
2028 KB |
Output is correct |
18 |
Correct |
14 ms |
2028 KB |
Output is correct |
19 |
Correct |
14 ms |
2156 KB |
Output is correct |
20 |
Correct |
17 ms |
2284 KB |
Output is correct |