#include <bits/stdc++.h>
#include "ricehub.h"
typedef std::pair<long long,long long> pli;
typedef std::pair<pli,long long> ppl;
ppl custo(long long P,long long R,int X[],long long B){
if(P<1)P=1;
std::vector<long long> vec;
for(int i=0;i!=R;++i){
long long dist = abs(X[i]-P);
vec.push_back(dist);
}
std::sort(vec.begin(),vec.end());
int res=0;long long u=0;
for(auto&x:vec){
if(x<=B){
++res;
B-=x;
continue;
}else {u+=x;}
}
return {{res,B},(1LL<<60LL)-u};
}
int besthub(int R, int L, int X[], long long B)
{
int la=1,ra=L;
while(ra-la>1){
int m = (la+ra)/2;
ppl alpha = custo(m,R,X,B);
ppl beta = custo(m+1,R,X,B);
if(alpha>beta){
ra=m;
}else {la=m;}
}
ppl ans={{0,0},0};
for(int i=-5;i!=6;++i){
ans=std::max(ans,custo(std::min(la+i,L),R,X,B));
}
return std::max(ans.first.first,std::max(custo(1,R,X,B).first.first,custo(L,R,X,B).first.first));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
21 |
Correct |
5 ms |
332 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
10 ms |
332 KB |
Output is correct |
24 |
Correct |
11 ms |
424 KB |
Output is correct |
25 |
Correct |
13 ms |
432 KB |
Output is correct |
26 |
Correct |
10 ms |
332 KB |
Output is correct |
27 |
Correct |
6 ms |
332 KB |
Output is correct |
28 |
Correct |
6 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
796 KB |
Output is correct |
2 |
Correct |
23 ms |
796 KB |
Output is correct |
3 |
Correct |
588 ms |
2676 KB |
Output is correct |
4 |
Correct |
617 ms |
2548 KB |
Output is correct |
5 |
Correct |
97 ms |
1640 KB |
Output is correct |
6 |
Correct |
74 ms |
1476 KB |
Output is correct |
7 |
Correct |
294 ms |
2488 KB |
Output is correct |
8 |
Correct |
335 ms |
2496 KB |
Output is correct |
9 |
Correct |
82 ms |
1524 KB |
Output is correct |
10 |
Correct |
68 ms |
1424 KB |
Output is correct |
11 |
Correct |
593 ms |
2516 KB |
Output is correct |
12 |
Correct |
601 ms |
2624 KB |
Output is correct |
13 |
Incorrect |
130 ms |
1432 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |