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 <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
const int MAXN = 1e5 + 10;
long long X[MAXN], SX[MAXN];
bool Teste(int R, int L, long long B, int tam)
{
for (int l = 1, r = tam; r <= R; l++, r++)
{
int m = (l + r) / 2;
long long sum = ((m - l + 1) * X[m]) - (SX[m] - SX[l-1]);
sum += (SX[r] - SX[m]) - ((r - m) * X[m]);
if (sum <= B) return true;
}
return false;
}
int besthub(int R, int L, int _X[], long long B)
{
for (int i = 1; i <= R; i++) X[i] = (long long)(_X[i-1]);
for (int i = 1; i <= R; i++) SX[i] = X[i] + SX[i-1];
int ini = 0; int fim = R;
while (ini < fim)
{
int m = (ini + fim) / 2;
if (ini == fim-1) m = fim;
if (Teste(R, L, B, m)) ini = m;
else fim = m-1;
}
return ini;
}
# | 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... |