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 lli long long int
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
lli n,l,b,ini,fin,mitad,res,centro;
lli arr[MAX+2];
bool sepuede(lli num) {
lli dif,sum = 0;
centro = (num+1)/2;
rep(i,1,num) sum += abs(arr[centro]-arr[i]);
if (sum <= b) return true;
rep(i,1,(n-num)) {
dif = arr[centro+1] - arr[centro];
sum -= arr[centro] - arr[i];
if (!(num&1)) sum -= dif;
centro++;
sum += arr[i+num] - arr[centro];
if (sum <= b) return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
n = R;
l = L;
rep(i,0,n-1) arr[i+1] = X[i];
b = B;
ini = 1;
fin = n;
while (ini <= fin) {
mitad = (ini+fin)/2;
if (sepuede(mitad)) {
ini = mitad+1;
res = mitad;
}
else fin = mitad-1;
}
return res;
}
# | 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... |