제출 #1279339

#제출 시각아이디문제언어결과실행 시간메모리
1279339LmaoLmao구경하기 (JOI13_watching)C++20
0 / 100
576 ms31852 KiB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define name "a"
using namespace std;

using ii = pair<int,int>;
using aa = array<int,3>;
const int N = 1e5+5;

int a[N];
int dp[2005][2005];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,p,q;
    cin >> n >> p >> q;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
    }
    sort(a+1,a+1+n);
    int l=1,r=1e9;
    int ans=0;
    while(l<=r) {
        int mid = l + r >> 1;
        dp[0][0]=0;
        bool c=0;
        //cout << mid << endl;
        for(int j=0;j<=n;j++) {
            int k=1;
            int huytran=1;
            for(int i=1;i<=n;i++) {
                while(k<=n && a[k]<=a[i]-mid) {
                    k++;
                }
                while(huytran<=n && a[huytran]<=a[i]-mid*2) {
                    huytran++;
                }
                dp[i][j]=1e9;
                if(j==0) {
                  dp[i][j]=dp[huytran-1][j]+1;
                } else
                dp[i][j]=min({dp[k-1][j-1],dp[huytran-1][j]+1});
                if(i==n && dp[i][j]<=p && j<=q) {
                    c=1;
                    //cout << "anhuytran " << i << ' ' << j << ' ' << dp[i][j] << endl;
                }
                //cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j] << endl;
            }
            //cout << endl;
        }
        //cout << endl;
        if(c) {
            ans=mid;
            r=mid-1;
        }
        else {
            l=mid+1;
        }
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...