이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf=1e9;
ll n, P, Q;
vector<ll> a;
ll L[2005][2];
ll dp[2005][2005];
bool check(ll w)
{
for(ll i=0; i<=n+2; i++)
{
for(ll j=0; j<=n+2; j++)
{
dp[i][j] = inf;
}
}
for(ll i=1; i<=n; i++)
{
L[i][0] = lower_bound(a.begin()+1,a.end(), a[i] - w + 1) - a.begin();
L[i][1] = lower_bound(a.begin()+1,a.end(), a[i] - 2 * w + 1) - a.begin();
}
for(ll i=0; i<=P; i++) dp[0][i] = 0;
for(ll i=1; i<=n; i++)
{
for(ll p=0; p<=P; p++)
{
dp[i][p] = min((p > 0 ? dp[L[i][0] - 1][p - 1] : inf), dp[L[i][1] - 1][p] + 1);
}
}
return dp[n][P] <= Q;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> P >> Q;
P = min(P, n);
Q = min(Q, n);
a.resize(n + 1);
for(ll i=1; i<=n; i++) cin >> a[i];
sort(a.begin()+1,a.end());
ll l = 1, r = inf, ans = 0;
while (l <= r)
{
int m = (l + r) >> 1;
if (check(m))
{
ans = m, r = m - 1;
}
else l = m + 1;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |