Submission #1298028

#TimeUsernameProblemLanguageResultExecution timeMemory
1298028ghammazhassanWatching (JOI13_watching)C++20
0 / 100
42 ms568 KiB
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
#define int long long
#define endl "\n"
#define fi first
#define se second
const int M=1203465797;
const int inf = 1e14;
const int LOG=18;
const int N=2e3+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;
int dp[N][N];
void solve(){   
    int p,q;
    cin >> n >> p >> q;
    vector<int>a(n+2);
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    if (p+q>=n){
        cout << 1 << endl;
        return;
    }
    sort(a.begin(),a.end());
    int l=0;
    int h=((int)1e9+p+q-1)/(p+q);
    int m=(l+h)/2;
    while (l<h){
        for (int i=0;i<=p;i++){
            for (int j=0;j<=q;j++){
                dp[i][j]=0;
            }
        }
        vector<int>rcp(n+2);
        vector<int>rcq(n+2);
        rcp[n+1]=rcq[n+1]=n;
        for (int i=1;i<=n;i++){
            for (int j=i;j<=n;j++){
                if (a[j]-a[i]<m){
                    rcp[i]=j;
                }
                if (a[j]-a[i]<2*m){
                    rcq[i]=j;
                }
            }
        }
        for (int i=0;i<=p;i++){
            for (int j=0;j<=q;j++){
                if (i){
                    dp[i][j]=max(dp[i][j],rcp[dp[i-1][j]+1]);
                }
                if (j){
                    dp[i][j]=max(dp[i][j],rcq[dp[i][j-1]+1]);
                }
            }
        }
        if (dp[p][q]==n){
            h=m;
        }
        else{
            l=m+1;
        }
        m=(l+h)/2;
    }
    cout << m << endl;


}
signed main()    
{   
    
    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
    cout << fixed << setprecision(9);
    srand(time(0));
    // int t=1;
    // cin >> t;
    for (int _=1;_<=t;_++){
        solve();
        q++;
    }
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...