Submission #1300173

#TimeUsernameProblemLanguageResultExecution timeMemory
1300173AbdullahIshfaqWatching (JOI13_watching)C++20
100 / 100
174 ms31920 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD 998244353
ll n, p, q, s = 1, e = 1e9 + 5, ans = 1e9 + 5;
ll dp[2005][2005], a[2005];
bool c(ll x)
{
	for (ll i = 1; i <= n; i++)
	{
		ll l = 1, r = 1;
		while (a[i] - a[l] >= x)
		{
			l++;
		}
		while (a[i] - a[r] >= 2 * x)
		{
			r++;
		}
		for (ll j = 0; j <= p; j++)
		{
			if (j == 0)
			{
				dp[i][j] = dp[r - 1][j] + 1;
			}
			else
			{
				dp[i][j] = min(dp[l - 1][j - 1], dp[r - 1][j] + 1);
			}
		}
	}
	return dp[n][p] <= q;
}
void solve()
{
	cin >> n >> p >> q;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	if (p + q >= n)
	{
		cout << 1 << '\n';
		exit(0);
	}
	sort(a + 1, a + n + 1);
	while (s <= e)
	{
		ll m = (s + e) / 2;
		memset(dp, 0, sizeof(dp));
		if (c(m))
		{
			ans = m;
			e = m - 1;
		}
		else
		{
			s = m + 1;
		}
	}
	cout << ans << '\n';
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t = 1;
	// cin >> t;
	// cout << fixed << setprecision(12);
	for (ll i = 1; i <= t; i++)
	{
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...