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;
const int nx=2e3+10;
int n, p, q, dp[nx][nx], ans;
vector<int> v;
bool can(int w)
{
for (int i=0; i<n; i++)
{
int ps=(upper_bound(v.begin(), v.end(), v[i]-w)-v.begin())-1;
int pb=(upper_bound(v.begin(), v.end(), v[i]-2*w)-v.begin())-1;
for (int j=0; j<=q; j++) dp[i][j]=1e9, dp[i][j]=min((pb==-1||j==0)?(j==0?nx:0):dp[pb][j-1], (ps==-1)?1:dp[ps][j]+1);
}
return dp[n-1][q]<=p;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>p>>q;
v.resize(n);
for (auto &x:v) cin>>x;
sort(v.begin(), v.end());
if (p+q>=n)
{
cout<<1;
return 0;
}
int l=1, r=1e9+1000;
while (l<r)
{
int md=(l+r)/2;
//cout<<md<<'\n';
if (can(md)) r=md;
else l=md+1;
}
cout<<r;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |