#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
bool check(int window, long long qs[], int R, long long B)
{
for (int m = (window + 1) / 2; m + (window / 2) <= R; ++m)
{
long long rightdis = qs[m + (window / 2)] - qs[m];
long long leftdis = qs[m - 1 + (window % 2 == 0)] - qs[m - (window / 2) + (window % 2 == 0) - 1];
long long cost = rightdis - leftdis;
if (cost <= B)
return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
long long dp[R + 1];
int ans = -1;
dp[0] = 0;
for (int i = 1; i <= R; ++i)
dp[i] = dp[i - 1] + X[i - 1];
int l = 0, r = R + 10;
while (l < r)
{
int mid = (l + r) / 2;
//cout << l << " " << mid << " " << r << "\n";
if (check(mid, dp, R, B))
{
l = mid + 1;
ans = max(mid, ans);
}
else
r = mid - 1;
}
cout << ans;
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |