Submission #1252319

#TimeUsernameProblemLanguageResultExecution timeMemory
1252319XXBabaProBerkay구경하기 (JOI13_watching)C++20
50 / 100
1093 ms15944 KiB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define MP make_pair
#define PB push_back

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using vec = vector<T>;

template<typename T, int N>
using arr = array<T, N>;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

const int INF = 1e9 + 7;

int dp[2001][2001];

int main()
{
	cin.tie(0) -> sync_with_stdio(0);

	int N, P, Q;
	cin >> N >> P >> Q;
	vec<int> A(N + 1);
	for (int i = 1; i <= N; i++)
		cin >> A[i];

	sort(A.begin() + 1, A.end());

	auto f = [&](int w) {
		for (int i = 1; i <= N; i++)
		{
			for (int j = 0; j <= min(N, Q); j++)
			{
				int x = upper_bound(A.begin() + 1, A.end(), A[i] - w) - A.begin();
				int y = upper_bound(A.begin() + 1, A.end(), A[i] - 2 * w) - A.begin();
				x--; y--;

				if (j == 0) dp[i][j] = dp[x][j] + 1;
				else dp[i][j] = min(dp[x][j] + 1, dp[y][j - 1]);
			}
		}

		return (dp[N][min(N, Q)] <= P);
	};

	int l = 1, r = 1e9;
	while (l <= r)
	{
		int m = (l + r) / 2;

		if (f(m)) r = m - 1;
		else l = m + 1;
	}

	cout << l << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...