#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5+10;
long long n, l;
long long a[maxn];
int besthub(int R, int L, int X[], long long B)
{
n = R;
l = L;
for (int i = 1; i <= n; ++ i)
{
a[i] = X[i-1];
}
int best = 0;
for (int i = 1; i <= n; ++ i)
{
for (int j = i; j <= n; ++ j)
{
int sz = j - i + 1;
int median = (j + i)/2;
int pos = a[median];
long long cost = 0;
for (int k = i; k <= j; ++ k)
{
cost += abs(a[k] - pos);
}
if(cost <= B)best = max(best, sz);
if(sz % 2 == 1)continue;
median ++;
pos = a[median];
cost= 0;
for (int k = i; k <= j; ++ k)
{
cost += abs(a[k] - pos);
}
if(cost <= B)best = max(best, sz);
}
}
return best;
}
# | 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... |