#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
#include <ricehub.h>
llo it[100001];
llo pre[100001];
llo n;
llo bb;
llo check(llo st,llo en){
llo mi=st+(en-st)/2;
llo co=(mi-st+1)*it[mi];
if(st==0){
co-=pre[mi];
}
else{
co-=(pre[mi]-pre[st-1]);
}
co-=(en-mi+1)*it[mi];
if(mi==0){
co+=pre[en];
}
else{
co+=(pre[en]-pre[mi-1]);
}
return co<=bb;
}
int besthub(int nn,int coo,int tt[],llo b){
n=(llo)nn;
llo l,r;
llo tot=0;
llo ma=0;
bb=b;
for(llo i=0;i<n;i++){
it[i]=(llo)tt[i];
}
pre[0]=it[0];
for(llo i=1;i<n;i++){
pre[i]=pre[i-1]+it[i];
}
for(llo i=0;i<n;i++){
llo low=i;
llo high=n-1;
while(low<high-1){
llo mid=(low+high)/2;
if(check(i,mid)){
low=mid;
}
else{
high=mid-1;
}
}
llo ans=low;
if(check(i,high)){
ans=high;
}
ma=max(ma,ans-i+1);
}
return ma;
/* for(llo i=0;i<n;i++){
if(i==0){
l=0;
r=-1;
for(llo j=0;j<n;j++){
if(tot+it[j]-it[0]<=b){
tot+=(it[j]-it[0]);
r+=1;
}
else{
break;
}
}
ma=max(ma,r-l+1);
}
else{
tot+=abs(it[i]-it[i-1])*abs(l-i);
tot-=abs(it[i]-it[i-1])*abs(r-i+1);
llo llp=l;
for(int j=llp;j<i;j++){
if(tot>b){
tot-=abs(it[j]-it[i]);
l+=1;
}
else{
break;
}
}
int rr=r;
for(llo j=rr+1;j<n;j++){
if(abs(it[j]-it[i])<=abs(it[i]-it[l])){
r+=1;
tot+=abs(it[j]-it[i]);
if(tot>b){
l+=1;
tot-=abs(it[i]-it[l-1]);
}
}
else if(abs(it[j]-it[i])+tot<=b){
r+=1;
tot+=abs(it[j]-it[i]);
}
else{
break;
}
}
ma=max(ma,r-l+1);
}
}*/
return ma;
}
/*int main(){
llo cc[5];
cc[0]=1;
cc[1]=2;
cc[2]=10;
cc[3]=12;
cc[4]=14;
cout<<besthub(5,20,cc,(llo)6)<<endl;
int r,l;
llo b;
cin>>r>>l>>b;
int ac[r];
for(int i=0;i<r;i++){
cin>>ac[i];
}
cout<<besthub(r,l,ac,b)<<endl;
return 0;
}*/
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, llo)':
ricehub.cpp:34:6: warning: unused variable 'l' [-Wunused-variable]
llo l,r;
^
ricehub.cpp:34:8: warning: unused variable 'r' [-Wunused-variable]
llo l,r;
^
ricehub.cpp:35:6: warning: unused variable 'tot' [-Wunused-variable]
llo tot=0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
6 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
896 KB |
Output is correct |
2 |
Correct |
9 ms |
896 KB |
Output is correct |
3 |
Correct |
28 ms |
3072 KB |
Output is correct |
4 |
Correct |
27 ms |
2936 KB |
Output is correct |
5 |
Correct |
18 ms |
1664 KB |
Output is correct |
6 |
Correct |
16 ms |
1664 KB |
Output is correct |
7 |
Correct |
26 ms |
2944 KB |
Output is correct |
8 |
Correct |
25 ms |
2944 KB |
Output is correct |
9 |
Correct |
15 ms |
1536 KB |
Output is correct |
10 |
Correct |
15 ms |
1664 KB |
Output is correct |
11 |
Correct |
29 ms |
2944 KB |
Output is correct |
12 |
Correct |
30 ms |
2932 KB |
Output is correct |
13 |
Correct |
16 ms |
1664 KB |
Output is correct |
14 |
Correct |
18 ms |
1664 KB |
Output is correct |
15 |
Correct |
23 ms |
2560 KB |
Output is correct |
16 |
Correct |
23 ms |
2560 KB |
Output is correct |
17 |
Correct |
27 ms |
2944 KB |
Output is correct |
18 |
Correct |
27 ms |
2944 KB |
Output is correct |
19 |
Correct |
28 ms |
3072 KB |
Output is correct |
20 |
Correct |
28 ms |
3064 KB |
Output is correct |