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"
#define sz(s) (int)s.size()
using namespace std;
#define ll long long
vector <int> v;
bool f(int x, ll b, int n){
ll k = 0, ind = x/2, in = x-1;
for(int i = 0; i < in; i++){
k += abs(v[ind]-v[i]);
}
while(in < n){
k += abs(v[in]-v[ind]);
if(k <= b) return true;
k -= (in-ind)*(v[ind+1]-v[ind]);
k += (ind-(in-x+1))*(v[ind+1]-v[ind]);
k -= (v[ind]-v[in-x+1]);
in++;
ind++;
}
return false;
}
int besthub(int n, int L, int a[], ll b){
for(int i = 0; i < n; i++) v.push_back(a[i]);
int l = 2, r = n, ans = 1;
while(l <= r){
int md = (l + r) / 2;
if(f(md,b,n) == 1){
l = md+1;
ans = md;
}
else {
r = md-1;
}
}
return ans;
}
# | 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... |