제출 #802765

#제출 시각아이디문제언어결과실행 시간메모리
80276512345678구경하기 (JOI13_watching)C++17
100 / 100
159 ms15956 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...