Submission #335889

# Submission time Handle Problem Language Result Execution time Memory
335889 2020-12-14T08:01:55 Z sumit_kk10 Rice Hub (IOI11_ricehub) C++14
100 / 100
63 ms 3308 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
 
long long int besthub(int n, int l, int a[], long long int b){
	long long int pre_sum[n] = {0}, suf_sum[n] = {0}, ans = 1;
	pre_sum[0] = a[0];
	suf_sum[n - 1] = a[n - 1];
	for(int i = 1; i < n; ++i)
		pre_sum[i] = pre_sum[i - 1] + a[i];
	for(int i = n - 2; i >= 0; --i)
		suf_sum[i] = suf_sum[i + 1] + a[i];
	for(int left = 0; left < n; ++left){
		int low = left + 1, high = n - 1;
		while(low <= high){
			int right = (low + high) / 2;
			long long int middle = (left + right) / 2;
			long long int val = pre_sum[right] - pre_sum[middle], val1 = suf_sum[left] - suf_sum[middle];
			val -= (a[middle] * (right - middle));
			val1 -= (a[middle] * (middle - left));
			val = abs(val), val1 = abs(val1);
			val += val1;
			// cout << left << ' ' << right << ' ' << middle << ' ' << val << '\n';
			if(val <= b){
				ans = max(ans, (long long int) right - left + 1);
				low  = right + 1;
			}
			else
				high = right - 1;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 3 ms 492 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 38 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 876 KB Output is correct
2 Correct 5 ms 876 KB Output is correct
3 Correct 63 ms 2812 KB Output is correct
4 Correct 25 ms 2796 KB Output is correct
5 Correct 42 ms 1644 KB Output is correct
6 Correct 11 ms 1644 KB Output is correct
7 Correct 23 ms 2796 KB Output is correct
8 Correct 24 ms 2796 KB Output is correct
9 Correct 12 ms 1644 KB Output is correct
10 Correct 12 ms 1644 KB Output is correct
11 Correct 25 ms 2796 KB Output is correct
12 Correct 25 ms 3308 KB Output is correct
13 Correct 12 ms 1644 KB Output is correct
14 Correct 15 ms 1644 KB Output is correct
15 Correct 18 ms 2540 KB Output is correct
16 Correct 19 ms 2540 KB Output is correct
17 Correct 22 ms 3052 KB Output is correct
18 Correct 22 ms 3052 KB Output is correct
19 Correct 23 ms 3308 KB Output is correct
20 Correct 24 ms 3216 KB Output is correct