Submission #280385

#TimeUsernameProblemLanguageResultExecution timeMemory
280385HeheheWatching (JOI13_watching)C++14
100 / 100
408 ms32120 KiB
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 2e3 + 11;
const int X = 1e6;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

//ifstream in(".in");
//ofstream out(".out");

int n, m, a[N], dp[N][N], S, B;

bool ok(int small, int big, int w){

    memset(dp, 0x3f, sizeof(dp));

    dp[0][0] = 0;

    for(int j = 1; j <= small; j++) dp[0][j] = 0;

    for(int i = 1; i <= n; i++){

        int x = (upper_bound(a + 1, a + n + 1, a[i] + w - 1) - a) - 1;
        int y = (upper_bound(a + 1, a + n + 1, a[i] + 2*w - 1) - a) - 1;

        for(int j = 0; j <= small; j++){
            if(j != small)dp[x][j + 1] = min(dp[x][j + 1], dp[i - 1][j]);
            dp[y][j] = min(dp[y][j], dp[i - 1][j] + 1);
        }
    }

    return (dp[n][small] <= big);
}

void solve(){

    cin >> n >> S >> B;

    S = min(S, n);
    B = min(B, n);

    for(int i = 1; i <= n; i++)cin >> a[i];

    sort(a + 1, a + n + 1);

    int l = 0, r = 1e9, ans = 0;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(ok(S, B, mid)){
            ans = mid;
            r = mid - 1;
        }else l = mid + 1;
    }

    cout << ans << '\n';

}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cout << setprecision(6) << fixed;

    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...