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;
typedef long long ll;
ll niz[100000];
ll mani;
int N;
bool moze(int x){
ll trencost=0;
int trenmid, r=x, l=1;
trenmid = (x+2)/2;
for(int i=1; i<=x; i++){
trencost += abs(niz[i]-niz[trenmid]);
}
if(trencost <= mani) return true;
while(r < N){
r++;
trenmid++;
trencost -= niz[trenmid-1]-niz[l];
trencost += niz[r]-niz[trenmid];
l++;
trencost += (niz[trenmid]-niz[trenmid-1])*(trenmid-l);
trencost -= (niz[trenmid]-niz[trenmid-1])*(r-trenmid);
if(trencost <= mani) return true;
}
return false;
}
int besthub(int n, int L, int X[], long long B){
N = n;
mani = B;
for(int i=1; i<=n; i++){
niz[i] = X[i-1];
}
int l=1, r=n;
int maxres=1;
while(l <= r){
int mid = (l+r)/2;
if(moze(mid)){
l = mid+1;
maxres = max(maxres, mid);
}
else r = mid-1;
}
return maxres;
}
# | 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... |