This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3+10;
const int INF = 1e9+10;
ll a[N], n, p, q;
ll dp[N][N];
bool check(ll w) {
for (int i=0; i<=n; ++i) {
for (int j=0; j<=n; ++j) dp[i][j]=INF;
}
dp[0][0]=0;
ll ppt=1, qpt=1;
for (int i=1; i<=n; ++i) {
while (a[i]-a[ppt]+1 > w) ++ppt;
while (a[i]-a[qpt]+1 > 2*w) ++qpt;
for (int j=1; j<=p; ++j) dp[i][j]=dp[ppt-1][j-1];
for (int j=0; j<=p; ++j) dp[i][j]=min(dp[i][j], dp[qpt-1][j]+1);
}
for (int i=0; i<=p; ++i) {
if (dp[n][i] <= q) return true;
} return false;
}
void solve() {
cin>>n>>p>>q;
for (int i=1; i<=n; ++i) cin>>a[i];
sort(a+1, a+n+1);
if (p+q >= n) {
cout<<1<<"\n";
return;
}
ll l=1, r=INF, res=INF;
while (l <= r) {
ll m=(l+r)/2;
if (check(m)) res=m, r=m-1;
else l=m+1;
} cout<<res<<"\n";
}
int main() {
int t=1; //cin>>t;
while (t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |