#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int besthub(int R, int L, int X[], long long B)
{
lli n=R,ls=0,us=0;
set<lli> l,u;
lli ans=0;
for(lli i=0;i<n;++i)
{
u.insert(X[i]);
us+=X[i];
if(u.size()>=l.size()+2)
{
l.insert((*u.begin()));
ls+=(*u.begin());
us-=(*u.begin());
u.erase(u.begin());
}
while((*u.begin())*l.size()-ls+us-(*u.begin())*u.size()>B)
{
ls-=(*l.begin());
l.erase(l.begin());
if(u.size()>=l.size()+2)
{
l.insert((*u.begin()));
ls+=(*u.begin());
us-=(*u.begin());
u.erase(u.begin());
}
}
ans=max(ans,lli(u.size()+l.size()));
}
return(ans);
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:35:60: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while((*u.begin())*l.size()-ls+us-(*u.begin())*u.size()>B)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Execution timed out |
1086 ms |
256 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Execution timed out |
1093 ms |
256 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
47 ms |
6520 KB |
Output is correct |
4 |
Correct |
47 ms |
6632 KB |
Output is correct |
5 |
Execution timed out |
1082 ms |
896 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |