Submission #139474

# Submission time Handle Problem Language Result Execution time Memory
139474 2019-07-31T20:18:44 Z Sorting Rice Hub (IOI11_ricehub) C++14
100 / 100
24 ms 2680 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 7;

long long b;
int l, r, *x;
long long prefix[N];

long long calc_sum(int from, int to){
	if(from == 0){
		return prefix[to];
	}
	return prefix[to] - prefix[from - 1];
}

long long find_score(int from, int to){
	long long mid;

	if((to - from) & 1){
		mid = (x[(to + from) / 2] + x[(to + from) / 2 + 1]) / 2;
	}
	else{
		mid = x[(to + from) / 2];
	}

	long long ans = ((to + from) / 2ll - from + 1ll) * mid - calc_sum(from, (to + from) / 2);
	ans += calc_sum((to + from) / 2 + 1, to) - (to - (to + from) / 2ll) * mid;

	return ans;
}

int besthub(int _r, int _l, int *_x, long long _b){
	r = _r;
	l = _l;
	x = _x;
	b = _b;

	int ans = 0;

	prefix[0] = x[0];
	for(int i = 1; i < r; i++){
		prefix[i] = x[i] + prefix[i - 1];
	}
	int j = 0;

	for(int i = 0; i < r; i++){
		for(j = max(i, j); j < r && find_score(i, j) <= b; j++);
		j--;
		ans = max(ans, j - i + 1);
	}

	return ans;
}	
# 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
# 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 380 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 256 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 376 KB Output is correct
10 Correct 2 ms 380 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 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 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 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 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 252 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 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 424 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 380 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 19 ms 1528 KB Output is correct
4 Correct 19 ms 2680 KB Output is correct
5 Correct 9 ms 1228 KB Output is correct
6 Correct 9 ms 1272 KB Output is correct
7 Correct 16 ms 2296 KB Output is correct
8 Correct 17 ms 2276 KB Output is correct
9 Correct 9 ms 1272 KB Output is correct
10 Correct 9 ms 1272 KB Output is correct
11 Correct 22 ms 2552 KB Output is correct
12 Correct 24 ms 2552 KB Output is correct
13 Correct 10 ms 1272 KB Output is correct
14 Correct 10 ms 1272 KB Output is correct
15 Correct 17 ms 2024 KB Output is correct
16 Correct 17 ms 1916 KB Output is correct
17 Correct 20 ms 2296 KB Output is correct
18 Correct 19 ms 2296 KB Output is correct
19 Correct 20 ms 2524 KB Output is correct
20 Correct 20 ms 2424 KB Output is correct