Submission #1327554

#TimeUsernameProblemLanguageResultExecution timeMemory
1327554nnargizWatching (JOI13_watching)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
//using namespace __gnu_pbds;
using namespace std;
const int mod = 998244353;
const int inf = 1e18;
const int maxx = 5e5 + 5;
const int lg = 26;
//typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

bool c (int w, vector <int>& a, int p, int q) {
    int i = 0, n = a.size();
    while (i < n && q > 0) {
        int end = a[i] + 2 * w;
        while (i < n && a[i] <= end) {
            i++;
        }
        q--;
    }
    while (i < n && p > 0) {
        int end = a[i] + w;
        while (i < n && a[i] <= end) {
            i++;
        }
        p--;
    }
    return i == n;
}

void solve () {
    int n, p, q, l = 1, r, ans;
    cin >> n >> p >> q;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    r = ans = a.back() - a.front() + 1;
    while (l <= r) {
        int m = l + (r - l) / 2;
        if (c(m, a, p, q)) {
            ans = m;
            r = m - 1;
        }
        else {
            l = m + 1;
        }
    }
    cout << ans - 1 << endl;
}

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

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