제출 #1354143

#제출 시각아이디문제언어결과실행 시간메모리
1354143SulA구경하기 (JOI13_watching)C++20
100 / 100
199 ms16244 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define popcount __builtin_popcount
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, p, q; cin >> n >> p >> q;
    p = min(p, n);
    q = min(q, n);

    long long A[n+1];
    for (int i = 0; i < n; cin >> A[i++]);
    A[n] = 2e9;
    sort(A, A + n);
    auto check = [&](int w) {
        vector<vector<int>> dp(n+1, vector<int>(p+1));
        int ptr1 = n, ptr2 = n;
        for (int i = n-1; i >= 0; i--) {
            dp[i].assign(p+1, 1e9);
            while (0 < ptr1 && A[i] + w   <= A[ptr1 - 1]) ptr1--;
            while (0 < ptr2 && A[i] + 2*w <= A[ptr2 - 1]) ptr2--;
            for (int j = 0; j <= p; j++) {
                dp[i][j] = dp[ptr2][j] + 1;
                if (0 < j)
                    dp[i][j] = min(dp[i][j], dp[ptr1][j-1]);
            }
        }
        return dp[0][p] <= q;
    };
    int l = 0, r = 1e9;
    while (r-l > 1) {
        int mid = (l+r)/2;
        (check(mid) ? r : l) = mid;
    }
    cout << r;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...