Submission #909576

# Submission time Handle Problem Language Result Execution time Memory
909576 2024-01-17T09:26:19 Z schzeey Watching (JOI13_watching) C++14
0 / 100
1000 ms 6232 KB
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
vector <int> arr;
bool check(int ans){
    vector<vector<int>> dp(a+1, vector<int>(n+1, 0));
    for (int i = 0; i < a+1; ++i){
        for (int j = 1; j <= n; ++j){
            int pa = j, pb = j;
            do pa--; while(arr[j]-arr[pa] <= ans);
            do pb--; while(arr[j]-arr[pb] <= 2*ans);

            if (i == 0) dp[i][j] = dp[i][pb]+1;
            else dp[i][j] = min(dp[i][pb]+1, dp[i-1][pa]);
        }
    }
    return dp[a][n] <= b;
}

int main(){
    cin >> n >> a >> b;
    arr.resize(n+1);
    for (int i = 1; i <= n; ++i) cin >> arr[i];
    if (a+b >= n) return cout<<1, 0;
    arr[0] = -1e9;
    sort(arr.begin(), arr.end());
    //for (auto e: arr) cout << e << " ";
    int lf = 0, ri = 1e9;
    while (lf <= ri){

        int mid = (lf+ri)/2;
        //cout << mid << " ";
        if (check(mid)) ri = mid-1;
        else lf = mid+1;

    }
    cout << lf+1;

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 360 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 256 ms 556 KB Output is correct
8 Correct 834 ms 1576 KB Output is correct
9 Execution timed out 1020 ms 6232 KB Time limit exceeded
10 Halted 0 ms 0 KB -