#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
if(R==1)
return 1;
int mediane = X[R/2];
int l = R/2-1, r = R/2+1;
int res = 1;
while((r<R||l>=0)&&(B>=0))
{
if(l<0)
{
res++;
B-=abs(mediane-X[r]);
r++;
}
else if(r==R)
{
res++;
B-=abs(mediane-X[l]);
l--;
}
else if(abs(X[l]-mediane)<=abs(X[r]-mediane))
{
res++;
B-=abs(mediane-X[l]);
l--;
}
else if(abs(X[l]-mediane)>abs(X[r]-mediane))
{
res++;
B-=abs(mediane-X[r]);
r++;
}
}
return res-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Incorrect |
15 ms |
1740 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |