#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int l=1;
int r=R;
int ans=1;
while(l<=r){
int mid=(l+r)/2;
int curpos=0;
long long hwl=1;
long long hwr=mid-1;
long long cur=0;
int cl=0;int cr=mid-1;
for(int i=1;i<mid;++i){
cur+=X[i]-X[0];
}
// cout<<mid<<" "<<cur<<endl;
if(cur<=B){
ans=mid;
l=mid+1;
continue;
}
// cout<<"h"<<endl;
bool ok=true;
while(cr<R){
while(hwl<hwr&&curpos<cr){
long long ds=(X[curpos+1]-X[curpos]);
cur-=(hwr-hwl)*ds;
hwl++;hwr--;
curpos++;
}
// cout<<cur<<" "<<hwl<<" "<<hwr<<" "<<cl<<" "<<cr<<endl;
if(cur<=B){
ok=false;
break;
}
cl++;cr++;
hwl--;hwr++;
cur-=X[curpos]-X[cl-1];
cur+=X[cr]-X[curpos];
}
if(ok){
r=mid-1;
}
else{
ans=mid;
l=mid+1;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
0 ms |
524 KB |
Output is correct |
4 |
Correct |
3 ms |
524 KB |
Output is correct |
5 |
Correct |
3 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
524 KB |
Output is correct |
2 |
Correct |
3 ms |
544 KB |
Output is correct |
3 |
Correct |
3 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
3 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
2 ms |
552 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
3 ms |
596 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
4 ms |
596 KB |
Output is correct |
25 |
Correct |
3 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
3 ms |
620 KB |
Output is correct |
3 |
Correct |
3 ms |
620 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
620 KB |
Output is correct |
15 |
Correct |
3 ms |
620 KB |
Output is correct |
16 |
Correct |
3 ms |
620 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
4 ms |
620 KB |
Output is correct |
19 |
Correct |
3 ms |
620 KB |
Output is correct |
20 |
Correct |
3 ms |
748 KB |
Output is correct |
21 |
Correct |
4 ms |
760 KB |
Output is correct |
22 |
Correct |
3 ms |
760 KB |
Output is correct |
23 |
Correct |
4 ms |
760 KB |
Output is correct |
24 |
Correct |
3 ms |
760 KB |
Output is correct |
25 |
Correct |
5 ms |
760 KB |
Output is correct |
26 |
Correct |
4 ms |
760 KB |
Output is correct |
27 |
Correct |
4 ms |
760 KB |
Output is correct |
28 |
Correct |
4 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
760 KB |
Output is correct |
2 |
Correct |
9 ms |
760 KB |
Output is correct |
3 |
Correct |
31 ms |
1020 KB |
Output is correct |
4 |
Correct |
34 ms |
1020 KB |
Output is correct |
5 |
Correct |
19 ms |
1020 KB |
Output is correct |
6 |
Correct |
18 ms |
1020 KB |
Output is correct |
7 |
Correct |
29 ms |
1020 KB |
Output is correct |
8 |
Correct |
19 ms |
1020 KB |
Output is correct |
9 |
Correct |
11 ms |
1020 KB |
Output is correct |
10 |
Correct |
11 ms |
1020 KB |
Output is correct |
11 |
Correct |
24 ms |
1020 KB |
Output is correct |
12 |
Correct |
32 ms |
1020 KB |
Output is correct |
13 |
Correct |
16 ms |
1148 KB |
Output is correct |
14 |
Correct |
16 ms |
1536 KB |
Output is correct |
15 |
Correct |
21 ms |
2564 KB |
Output is correct |
16 |
Correct |
20 ms |
3224 KB |
Output is correct |
17 |
Correct |
22 ms |
4248 KB |
Output is correct |
18 |
Correct |
23 ms |
5212 KB |
Output is correct |
19 |
Correct |
24 ms |
6272 KB |
Output is correct |
20 |
Correct |
24 ms |
7148 KB |
Output is correct |