Submission #684177

# Submission time Handle Problem Language Result Execution time Memory
684177 2023-01-20T15:19:50 Z sudheerays123 Rice Hub (IOI11_ricehub) C++17
100 / 100
14 ms 3276 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll int
const ll N = 100+5 , INF = 1e9 , MOD = 1e9+7;

int besthub(int R, int L, int X[], long long B){

	ll n = R;
	vector<long long> a(n+5),presum(n+5);
	for(ll i = 1; i <= n; i++){
		a[i] = X[i-1];
		presum[i] = presum[i-1]+a[i];
	}

	ll low = 1 , high = n;
	ll ans;

	function<bool(ll)> check = [&](ll l){

		for(ll i = 1; i <= n-l+1; i++){
			ll j = i+l-1;
			ll mid = (i+j)/2;

			long long cost = (mid-i)*a[mid]-presum[mid-1]+presum[i-1]+presum[j]-presum[mid]-(j-mid)*a[mid];
			if(cost <= B) return true;
		}

		return false;
	};

	while(low <= high){
		ll mid = (low+high)/2;
		if(check(mid)){
			ans = mid;
			low = mid+1;
		}
		else high = mid-1;
	}

	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:42:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |  return ans;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 260 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 268 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 11 ms 2232 KB Output is correct
4 Correct 12 ms 2212 KB Output is correct
5 Correct 7 ms 1640 KB Output is correct
6 Correct 7 ms 1620 KB Output is correct
7 Correct 11 ms 3044 KB Output is correct
8 Correct 12 ms 3044 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 6 ms 1476 KB Output is correct
11 Correct 13 ms 3276 KB Output is correct
12 Correct 12 ms 3228 KB Output is correct
13 Correct 7 ms 1608 KB Output is correct
14 Correct 7 ms 1620 KB Output is correct
15 Correct 9 ms 2476 KB Output is correct
16 Correct 9 ms 2472 KB Output is correct
17 Correct 11 ms 2984 KB Output is correct
18 Correct 14 ms 3020 KB Output is correct
19 Correct 12 ms 3148 KB Output is correct
20 Correct 12 ms 3148 KB Output is correct