#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
long long int besthub(int n, int l, int a[], long long int b){
long long int pre_sum[n] = {0}, suf_sum[n] = {0};
pre_sum[0] = a[0];
suf_sum[n - 1] = a[n - 1];
for(int i = 1; i < n; ++i)
pre_sum[i] = pre_sum[i - 1] + a[i];
for(int i = n - 2; i >= 0; --i)
suf_sum[i] = suf_sum[i + 1] + a[i];
long long int ans = 1;
for(int i = 0; i < n; ++i){
int low = i + 1, high = n - 1, cur = i, cur1 = i;
while(low <= high){
int mid = (low + high) / 2;
long long int x = pre_sum[mid] - pre_sum[i];
x -= (a[i] * (mid - i));
if(x > b)
high = mid - 1;
else{
low = mid + 1;
cur = mid;
}
}
if(i != 0){
low = 0, high = i - 1;
while(low <= high){
int mid = (low + high) / 2;
long long int x = suf_sum[mid] - suf_sum[i];
x -= (a[i] * (mid - i));
if(x > b)
low = mid + 1;
else{
cur1 = mid;
high = mid - 1;
}
}
}
ans = max(ans, (long long int) cur - cur1 + 1);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |