#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sp <<" "<<
#define endl "\n"
int besthub(int R, int L, int X[], ll B) {
int best = 0;
auto process = [&](int x) -> int {
int res = 0;
ll have = B;
priority_queue<ll, vector<ll>, greater<ll>> st;
for (int i = 0; i < R; i++) {
st.push(abs(X[i] - x));
}
while (!st.empty()) {
int take = st.top(); st.pop();
if (take > have) break;
res++;
have -= take;
}
return res;
};
// try placing
for (int i = 0; i < R; i++) {
best = max(best, process(X[i]));
}
return best;
}
# | 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... |