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"
#define ll long long
using namespace std;
bool check(int k, ll B, vector<int>&arr){
ll cost = 0;
int n = arr.size(), p = (k-1) / 2;
for (int i = 0; i < k; i++)
cost += abs(arr[i] - arr[p]);
if (cost <= B)
return true;
for (int i = k; i < n; i++){
int y = arr[i], x = arr[i - k];
int m = arr[p], mp = arr[p+1];
p += 1;
if (k&1){
cost += y + x;
cost -= m + mp;
}
else{
cost += y + x;
cost -= mp + mp;
}
if (cost <= B)
return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B){
vector<int> arr;
for (int i = 0; i < R; i++)
arr.push_back(X[i]);
int st = 1, en = R;
while (st < en){
int mid = (st + en + 1) >> 1;
if (check(mid, B, arr))
st = mid;
else
en = mid - 1;
}
return st;
}
# | 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... |