#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 |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
288 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
640 KB |
Output is correct |
2 |
Correct |
37 ms |
640 KB |
Output is correct |
3 |
Correct |
317 ms |
1404 KB |
Output is correct |
4 |
Correct |
316 ms |
1404 KB |
Output is correct |
5 |
Incorrect |
80 ms |
896 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |