Submission #91238

# Submission time Handle Problem Language Result Execution time Memory
91238 2018-12-26T15:47:43 Z arman_ferdous Rice Hub (IOI11_ricehub) C++17
17 / 100
328 ms 12500 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e5+10;

int n; ll arr[N], sum[N];

ll get(ll l, ll r, ll M) {
	ll ret = 0;
	if(arr[r] <= M) return (r - l + 1) * M - sum[r] + sum[l-1];
	if(M <= arr[l]) return sum[r] - sum[l-1] - (r - l + 1) * M;
	int p = lower_bound(arr,arr+n,M) - arr;
	return M * (p - l) - sum[p-1] + sum[l-1] + sum[r] - sum[p-1] - M * (r - p + 1);
}

int besthub(int R, int L, int X[], ll B) {
	n = R;
	for(int i = 1; i <= n; i++) arr[i] = X[i-1];
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + arr[i];

	int lo = 1, hi = n, ans = 1;
	while(lo <= hi) {
		int mid = (lo + hi) >> 1;
		int can = 0;
		for(int i = 1; i + mid - 1 <= n; i++) {
			ll avg = (sum[i + mid - 1] - sum[i - 1]) / mid;
			for(ll M = avg - 10; M <= avg + 10; M++)
				if(get(i, i + mid - 1, M) <= B) { can = 1; break; }
			if(can) break;
		} 
		if(can) ans = mid, lo = mid + 1;
		else hi = mid - 1;
	} return ans;
}

Compilation message

ricehub.cpp: In function 'll get(ll, ll, ll)':
ricehub.cpp:11:5: warning: unused variable 'ret' [-Wunused-variable]
  ll ret = 0;
     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 2 ms 572 KB Output is correct
3 Correct 2 ms 580 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 648 KB Output is correct
2 Correct 2 ms 692 KB Output is correct
3 Correct 2 ms 696 KB Output is correct
4 Correct 2 ms 792 KB Output is correct
5 Correct 2 ms 796 KB Output is correct
6 Correct 2 ms 808 KB Output is correct
7 Correct 2 ms 824 KB Output is correct
8 Correct 2 ms 832 KB Output is correct
9 Correct 2 ms 832 KB Output is correct
10 Correct 2 ms 836 KB Output is correct
11 Correct 2 ms 840 KB Output is correct
12 Correct 2 ms 844 KB Output is correct
13 Correct 2 ms 848 KB Output is correct
14 Correct 2 ms 852 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 2 ms 864 KB Output is correct
18 Correct 2 ms 868 KB Output is correct
19 Correct 2 ms 872 KB Output is correct
20 Correct 2 ms 876 KB Output is correct
21 Correct 3 ms 880 KB Output is correct
22 Correct 3 ms 884 KB Output is correct
23 Correct 2 ms 888 KB Output is correct
24 Correct 2 ms 892 KB Output is correct
25 Correct 2 ms 896 KB Output is correct
26 Correct 2 ms 900 KB Output is correct
27 Incorrect 3 ms 904 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 908 KB Output is correct
2 Correct 2 ms 912 KB Output is correct
3 Correct 2 ms 960 KB Output is correct
4 Correct 2 ms 968 KB Output is correct
5 Correct 2 ms 1008 KB Output is correct
6 Correct 2 ms 1012 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1116 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 4 ms 1184 KB Output is correct
13 Correct 2 ms 1184 KB Output is correct
14 Correct 2 ms 1208 KB Output is correct
15 Correct 3 ms 1208 KB Output is correct
16 Correct 2 ms 1208 KB Output is correct
17 Correct 2 ms 1208 KB Output is correct
18 Correct 2 ms 1208 KB Output is correct
19 Correct 2 ms 1208 KB Output is correct
20 Correct 2 ms 1208 KB Output is correct
21 Correct 13 ms 1208 KB Output is correct
22 Correct 13 ms 1208 KB Output is correct
23 Correct 2 ms 1340 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1404 KB Output is correct
26 Correct 2 ms 1444 KB Output is correct
27 Incorrect 12 ms 1484 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 1924 KB Output is correct
2 Correct 134 ms 2056 KB Output is correct
3 Correct 15 ms 4604 KB Output is correct
4 Correct 16 ms 5664 KB Output is correct
5 Correct 256 ms 5664 KB Output is correct
6 Correct 252 ms 5664 KB Output is correct
7 Correct 14 ms 7164 KB Output is correct
8 Correct 14 ms 7936 KB Output is correct
9 Correct 228 ms 7936 KB Output is correct
10 Correct 244 ms 7936 KB Output is correct
11 Correct 17 ms 9544 KB Output is correct
12 Correct 17 ms 10608 KB Output is correct
13 Correct 328 ms 10608 KB Output is correct
14 Correct 299 ms 10608 KB Output is correct
15 Correct 13 ms 11712 KB Output is correct
16 Incorrect 13 ms 12500 KB Output isn't correct
17 Halted 0 ms 0 KB -