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>
using namespace std;
#include "ricehub.h"
typedef long long ll;
priority_queue<int,vector<int>, greater<int> > pq;
int besthub(int R, int L, int X[],ll B){
ll n = R, ans = -1, act, sum;
ll low = 1, high = L;
while(low < high){
ll mid = (low + high) / 2;
ll midleft = (low + mid) / 2, midright = (mid + high) / 2;
ll distsleft = 0, distsright = 0;
for(ll j = 0; j < n; j++){
distsleft += abs(midleft - X[j]);
distsright += abs(midright - X[j]);
}
for(ll j = 0; j < n; j++){
pq.push(abs(mid - X[j]));
}
sum = act = 0;
while(!pq.empty()){
if(sum + pq.top() > B){
pq.pop();
continue;
}else{
sum += pq.top();
act++;
}
pq.pop();
}
ans = max(ans,act);
if(distsleft < distsright){
high = mid;
}else{
low = mid+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... |