Submission #392620

# Submission time Handle Problem Language Result Execution time Memory
392620 2021-04-21T11:18:13 Z ritul_kr_singh Rice Hub (IOI11_ricehub) C++17
100 / 100
30 ms 2520 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include "ricehub.h"

int besthub(int n, int L, int X[], ll B){
	ll pre[n+1] = {0};
	for(int i=0; i<n; ++i) pre[i+1] = (ll)X[i] + pre[i];
	int ans = 1;

	for(int i=1; i<=n; ++i){
		int low = i, high = n;
		while(low < high){
			int mid = (low + high) / 2;
			++mid;

			int mx = (mid + i) / 2;
			ll cost = 0, pos = X[mx - 1];
			if(i < mx){
				ll s = pre[mx-1] - pre[i-1];
				cost += pos * (mx - i) - s;
			}
			if(mx < mid){
				ll s = pre[mid] - pre[mx];
				cost += s - pos * (mid - mx);
			}
			if(cost <= B) low = mid;
			else high = mid - 1;
		}
		ans = max(ans, low - i + 1);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 324 KB Output is correct
23 Correct 2 ms 320 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 456 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 320 KB Output is correct
28 Correct 2 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 588 KB Output is correct
2 Correct 5 ms 588 KB Output is correct
3 Correct 30 ms 2508 KB Output is correct
4 Correct 28 ms 2520 KB Output is correct
5 Correct 13 ms 1100 KB Output is correct
6 Correct 13 ms 1216 KB Output is correct
7 Correct 26 ms 2252 KB Output is correct
8 Correct 26 ms 2244 KB Output is correct
9 Correct 13 ms 1100 KB Output is correct
10 Correct 13 ms 1172 KB Output is correct
11 Correct 30 ms 2516 KB Output is correct
12 Correct 30 ms 2508 KB Output is correct
13 Correct 14 ms 1248 KB Output is correct
14 Correct 13 ms 1228 KB Output is correct
15 Correct 21 ms 1868 KB Output is correct
16 Correct 24 ms 1960 KB Output is correct
17 Correct 26 ms 2236 KB Output is correct
18 Correct 25 ms 2252 KB Output is correct
19 Correct 26 ms 2308 KB Output is correct
20 Correct 27 ms 2400 KB Output is correct