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"
using namespace std;
typedef long long ll;
ll n; ll place, cap;
vector<ll> v;
bool cmp(ll a, ll b) {
return abs(a-place) < abs(b-place);
}
ll calc(ll x) {
place = x;
sort(v.begin(),v.end(),cmp);
ll have = cap; ll ret = 0;
for(ll i = 0; i < n; i++) {
if(abs(v[i]-x) > have) break;
have -= abs(v[i]-x);
ret++;
} return ret;
}
int besthub(int R, int L, int X[], ll B) {
n = R; cap = B;
for(ll i = 0; i < R; i++) v.push_back(X[i]);
ll lo = 0, hi = L;
while(hi - lo >= 30) {
ll mid1 = (lo + lo + hi)/3;
ll mid2 = (lo + hi + hi)/3;
ll got1 = calc(mid1), got2 = calc(mid2);
if(got1 > got2) hi = mid2 - 1;
else lo = mid1 + 1;
}
ll ret = 0;
for(ll i = lo; i <= hi; i++)
ret = max(ret , calc(i));
return ret;
}
# | 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... |