#include "ricehub.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
multiset<int>lept,rigt;
ll s1,s2;
void fix(){
int sz=lept.size()+rigt.size();
while(lept.size()>(sz+1)/2){
int x=*lept.rbegin();
rigt.insert(x);
lept.erase(lept.find(x));
s1-=x;
s2+=x;
}
while(rigt.size()>sz/2){
int x=*rigt.begin();
lept.insert(x);
rigt.erase(rigt.find(x));
s1+=x;
s2-=x;
}
}
void ins(int x){
if(lept.empty()){
lept.insert(x);
s1+=x;
return;
}
int mid=*lept.rbegin();
if(x>mid) rigt.insert(x),s2+=x;
else lept.insert(x),s1+=x;
fix();
}
void erase(int x){
int mid=*lept.rbegin();
if(x>mid) rigt.erase(rigt.find(x)),s2-=x;
else lept.erase(lept.find(x)),s1-=x;
fix();
}
int besthub(int R, int L, int X[], long long B){
int l=1,r=R+1;
while(r-l>1){
int mid=(l+r)/2;
bool ok=false;
s1=0,s2=0;
for(int i=0;i<R;i++){
ins(X[i]);
if(i>=mid) erase(X[i-mid]);
if(i>=mid-1){
ll x=*lept.rbegin();
ok=ok?ok:(ll)lept.size()*x-s1+s2-(ll)rigt.size()*x<=B;
}
}
multiset<int>g,j;
swap(g,lept);
swap(j,rigt);
if(ok) l=mid;
else r=mid;
}
return l;
}
Compilation message
ricehub.cpp: In function 'void fix()':
ricehub.cpp:11:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
11 | while(lept.size()>(sz+1)/2){
| ~~~~~~~~~~~^~~~~~~~~
ricehub.cpp:18:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
18 | while(rigt.size()>sz/2){
| ~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
448 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
444 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
440 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
448 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
8 ms |
604 KB |
Output is correct |
22 |
Correct |
8 ms |
608 KB |
Output is correct |
23 |
Correct |
7 ms |
604 KB |
Output is correct |
24 |
Correct |
7 ms |
604 KB |
Output is correct |
25 |
Correct |
8 ms |
600 KB |
Output is correct |
26 |
Correct |
8 ms |
604 KB |
Output is correct |
27 |
Correct |
8 ms |
604 KB |
Output is correct |
28 |
Correct |
8 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
860 KB |
Output is correct |
2 |
Correct |
40 ms |
1112 KB |
Output is correct |
3 |
Correct |
315 ms |
8272 KB |
Output is correct |
4 |
Correct |
333 ms |
8376 KB |
Output is correct |
5 |
Correct |
139 ms |
3928 KB |
Output is correct |
6 |
Correct |
139 ms |
3932 KB |
Output is correct |
7 |
Correct |
336 ms |
8072 KB |
Output is correct |
8 |
Correct |
327 ms |
8020 KB |
Output is correct |
9 |
Correct |
160 ms |
4180 KB |
Output is correct |
10 |
Correct |
152 ms |
4104 KB |
Output is correct |
11 |
Correct |
316 ms |
8340 KB |
Output is correct |
12 |
Correct |
338 ms |
8508 KB |
Output is correct |
13 |
Correct |
129 ms |
4188 KB |
Output is correct |
14 |
Correct |
135 ms |
4188 KB |
Output is correct |
15 |
Correct |
224 ms |
6712 KB |
Output is correct |
16 |
Correct |
233 ms |
6740 KB |
Output is correct |
17 |
Correct |
280 ms |
7764 KB |
Output is correct |
18 |
Correct |
285 ms |
7760 KB |
Output is correct |
19 |
Correct |
310 ms |
7936 KB |
Output is correct |
20 |
Correct |
313 ms |
8020 KB |
Output is correct |