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;
#define m_p make_pair
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int N = 100005;
int n, d;
int x[N];
ll b;
ll p[N];
bool stg(int q)
{
for (int l = 1; l <= n - q + 1; ++l)
{
int r = l + q - 1;
int m = (l + r) / 2;
ll yb = 0;
yb += (m - l + 1) * 1LL * x[m];
yb -= (p[m] - p[l - 1]);
yb += (p[r] - p[m - 1]);
yb -= (r - m + 1) * 1LL * x[m];
if (yb <= b)
return true;
}
return false;
}
int solv()
{
for (int i = 1; i <= n; ++i)
p[i] = p[i - 1] + x[i];
int ans = 0;
int l = 1, r = n;
while (l <= r)
{
int m = (l + r) / 2;
if (stg(m))
{
ans = m;
l = m + 1;
}
else
{
r = m - 1;
}
}
return ans;
}
int besthub(int R, int L, int X[], ll B)
{
n = R;
d = L;
for (int i = 1; i <= n; ++i)
x[i] = X[i - 1];
b = B;
return solv();
}
# | 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... |