Submission #856124

# Submission time Handle Problem Language Result Execution time Memory
856124 2023-10-02T17:12:58 Z aykhn Rice Hub (IOI11_ricehub) C++14
49 / 100
12 ms 5212 KB
#include "ricehub.h"
#include <bits/stdc++.h>

// author : aykhn

using namespace std;
typedef long long ll;

#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F

int besthub(int n, int L, int X[], long long b)
{
	ll x[n];
	for (int i = 0; i < n; i++) x[i] = X[i];
	vector<ll> pref(n + 1);
	pref[0] = x[0];
	for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + x[i];
	pref[n] = pref[n - 1];
	int ans = 1;
	int l = 0;
	int r = 1;
	for (int i = 0; i < n; i++)
	{
		ll sum = x[i] * (i - l + 1) - (pref[i] - (l ? pref[l - 1] : 0));
		sum += pref[r - 1] - (i ? pref[i - 1] : 0) - x[i] * (r - i); 
		while (l < n)
		{
			if (sum <= b) break;
			sum -= abs(x[i] - x[l]);
			l++;
		} 
		while (r < n)
		{
			if (sum + x[r] - x[i] <= b)
			{
				sum += x[r] - x[i];
				r++;
			}
			else break;
		}
		while (r < n && abs(x[l] - x[i]) > abs(x[r] - x[i]))
		{
			sum -= abs(x[l] - x[i]);
			sum += abs(x[r] - x[i]);
			l++;
			r++;
		}
		ans = max(ans, r - l);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Incorrect 0 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 12 ms 4188 KB Output is correct
4 Correct 11 ms 4188 KB Output is correct
5 Correct 5 ms 3676 KB Output is correct
6 Correct 5 ms 3672 KB Output is correct
7 Correct 9 ms 4916 KB Output is correct
8 Correct 9 ms 4956 KB Output is correct
9 Correct 5 ms 3676 KB Output is correct
10 Correct 4 ms 3536 KB Output is correct
11 Correct 11 ms 5212 KB Output is correct
12 Correct 11 ms 5212 KB Output is correct
13 Correct 5 ms 3928 KB Output is correct
14 Correct 5 ms 3800 KB Output is correct
15 Correct 8 ms 4444 KB Output is correct
16 Correct 9 ms 4408 KB Output is correct
17 Correct 9 ms 4956 KB Output is correct
18 Correct 11 ms 4968 KB Output is correct
19 Correct 10 ms 4948 KB Output is correct
20 Correct 11 ms 4956 KB Output is correct