This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int maxR = 1e5 + 5;
#define ll long long
ll dp[maxR];
bool check(int window, int R, long long B)
{
for (int m = (window + 1) / 2; m + (window / 2) <= R; ++m)
{
ll rightdis = dp[m + (window / 2)] - dp[m];
ll leftdis = dp[m - 1 + (window % 2 == 0)] - dp[m - (window / 2) + (window % 2 == 0) - 1];
ll cost = rightdis - leftdis;
if (cost <= B)
return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
dp[0] = 0;
for (int i = 0; i < R; ++i)
dp[i + 1] = dp[i] + X[i];
int l = 0, r = R + 10, ans = -1;
while (l <= r)
{
int mid = (l + r) / 2;
//cout << l << " " << mid << " " << r << "\n";
if (check(mid, R, B))
{
l = mid + 1;
ans = mid;
}
else
r = mid - 1;
}
//cout << ans;
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |