Submission #1290039

#TimeUsernameProblemLanguageResultExecution timeMemory
1290039BahaminWatching (JOI13_watching)C++20
100 / 100
86 ms15324 KiB
#include <bits/stdc++.h>

using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define sui cout.tie(NULL); cin.tie(NULL); ios_base::sync_with_stdio(false)
const int MAX_N = 2e3 + 5;
const int MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
const int LOG = 30;

int n, p, q;
int a[MAX_N];

bool check(int x)
{
    int dp[n + 1][q + 1];
    for (int i = 0; i <= q; i++) dp[n][i] = 0;
    int last1 = n;
    int last2 = n;
    for (int i = n - 1; i >= 0; i--)
    {
        while (a[last1 - 1] - a[i] >= x) last1--;
        while (a[last2 - 1] - a[i] >= 2 * x) last2--;
        for (int j = 0; j <= q; j++)
        {
            dp[i][j] = 1 + dp[last1][j];
            if (j) dp[i][j] = min(dp[i][j], dp[last2][j - 1]);
        }
    }
    if (dp[0][q] <= p) return true;
    return false;
}

void solve() {
    cin >> n >> p >> q;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    if (p + q >= n) 
    {
        cout << 1 << "\n";
        return;
    }
    int l = 0;
    int r = INF;
    while (r - l > 1)
    {
        int mid = (r + l) >> 1;
        if (check(mid)) r = mid;
        else l = mid;
    }
    cout << r << "\n";   
}

int main() {
    sui;
    int tc = 1;
    //cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...