Submission #163183

# Submission time Handle Problem Language Result Execution time Memory
163183 2019-11-11T16:47:57 Z kostia244 Rice Hub (IOI11_ricehub) C++17
100 / 100
51 ms 6520 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll sumlo = 0, sumhi = 0;
multiset<ll> lo, hi;
ll eval() {
	ll med = *lo.rbegin();
	return (lo.size() * med - sumlo) + (sumhi - hi.size() * med);
}
void balance() {
	while (lo.size() < hi.size()) {
		sumhi -= *hi.begin();
		sumlo += *hi.begin();
		lo.insert(*hi.begin());
		hi.erase(hi.begin());
	}
}
void pop() {
	sumlo -= *lo.begin();
	lo.erase(lo.begin());
	balance();
}
void push(ll x) {
	hi.insert(x);
	sumhi += x;
	balance();
}
int besthub(int R, int L, int X[], long long B) {
	ll ans = 0;
	for(int i = 0; i < R; i++) {
		push(X[i]);
		while(eval()>B) pop();
		ans = max(ans, (ll)lo.size()+(ll)hi.size());
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 380 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 252 KB Output is correct
23 Correct 2 ms 404 KB Output is correct
24 Correct 2 ms 372 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 4 ms 328 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 0 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 504 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 50 ms 6520 KB Output is correct
4 Correct 49 ms 6496 KB Output is correct
5 Correct 17 ms 888 KB Output is correct
6 Correct 17 ms 888 KB Output is correct
7 Correct 47 ms 6264 KB Output is correct
8 Correct 46 ms 6236 KB Output is correct
9 Correct 20 ms 1144 KB Output is correct
10 Correct 20 ms 1144 KB Output is correct
11 Correct 50 ms 6464 KB Output is correct
12 Correct 51 ms 6452 KB Output is correct
13 Correct 22 ms 888 KB Output is correct
14 Correct 20 ms 888 KB Output is correct
15 Correct 43 ms 4932 KB Output is correct
16 Correct 36 ms 4856 KB Output is correct
17 Correct 45 ms 5752 KB Output is correct
18 Correct 44 ms 5880 KB Output is correct
19 Correct 48 ms 6228 KB Output is correct
20 Correct 47 ms 6136 KB Output is correct