Submission #946589

# Submission time Handle Problem Language Result Execution time Memory
946589 2024-03-14T19:12:35 Z VMaksimoski008 Watching (JOI13_watching) C++14
100 / 100
196 ms 16500 KB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int> > dp(2005, vector<int>(2005, 1e9));

int main() {
    int n, p, q, i, j;
    cin >> n >> p >> q;

    p = min(n, p);
    q = min(n, q);

    vector<int> v(n+1, -1e9);
    for(i=1; i<=n; i++) cin >> v[i];
    sort(v.begin()+1, v.end());

    auto f = [&](int m) {
        for(int i=0; i<=n; i++)
            for(int j=0; j<=p; j++) dp[i][j] = 1e9;
        dp[0][0] = 0;

        int k=0, l=0;
        for(i=1; i<=n; i++) {
            while(v[i] - v[k] >= m) k++;
            while(v[i] - v[l] >= 2 * m) l++;
            for(j=0; j<=p; j++) {
                if(j) dp[i][j] = dp[k-1][j-1];
                dp[i][j] = min(dp[i][j], dp[l-1][j] + 1);
            }
        }

        for(i=0; i<=p; i++)
            if(dp[n][i] <= q) return 1;
        return 0;
    };

    int l=1, r=1e9, ans = 1e9;
    while(l <= r) {
        int m = (l + r) / 2;
        if(f(m)) ans = m, r = m - 1;
        else l = m + 1;
    }

    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16220 KB Output is correct
2 Correct 8 ms 16220 KB Output is correct
3 Correct 8 ms 16216 KB Output is correct
4 Correct 8 ms 16220 KB Output is correct
5 Correct 8 ms 16220 KB Output is correct
6 Correct 9 ms 16220 KB Output is correct
7 Correct 9 ms 16220 KB Output is correct
8 Correct 8 ms 16220 KB Output is correct
9 Correct 8 ms 16220 KB Output is correct
10 Correct 8 ms 16220 KB Output is correct
11 Correct 8 ms 16116 KB Output is correct
12 Correct 8 ms 16220 KB Output is correct
13 Correct 8 ms 16220 KB Output is correct
14 Correct 8 ms 16220 KB Output is correct
15 Correct 8 ms 16216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16220 KB Output is correct
2 Correct 9 ms 16220 KB Output is correct
3 Correct 151 ms 16220 KB Output is correct
4 Correct 162 ms 16220 KB Output is correct
5 Correct 17 ms 16216 KB Output is correct
6 Correct 196 ms 16464 KB Output is correct
7 Correct 10 ms 16500 KB Output is correct
8 Correct 21 ms 16220 KB Output is correct
9 Correct 74 ms 16220 KB Output is correct
10 Correct 173 ms 16228 KB Output is correct
11 Correct 17 ms 16220 KB Output is correct
12 Correct 101 ms 16232 KB Output is correct
13 Correct 10 ms 16220 KB Output is correct
14 Correct 11 ms 16248 KB Output is correct
15 Correct 10 ms 16252 KB Output is correct