Submission #975876

# Submission time Handle Problem Language Result Execution time Memory
975876 2024-05-06T01:46:26 Z vjudge1 Watching (JOI13_watching) C++17
0 / 100
1000 ms 344 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N, P, Q;
    cin >> N >> P >> Q;

    vector<int> lanes(N);
    for (int i = 0; i < N; ++i) {
        cin >> lanes[i];
    }

    // Sort the lanes in ascending order
    sort(lanes.begin(), lanes.end());

    int min_k = lanes[N - 1] - lanes[0] + 1; // Minimum k to cover all lanes

    // Check all possible values of k
    for (int k = 1; k <= lanes[N - 1] - lanes[0] + 1; ++k) {
        int used_P = 0; // Number of small detectors used
        int used_Q = 0; // Number of large detectors used
        int start = lanes[0];

        // Iterate through lanes and count used detectors
        for (int i = 0; i < N; ++i) {
            if (lanes[i] > start + k - 1) {
                if (lanes[i] - start <= 2 * k - 1) {
                    used_P++;
                } else {
                    used_Q++;
                }
                start = lanes[i] + 1;
            }
        }

        // Update minimum k if necessary
        if (used_P <= P && used_Q <= Q) {
            min_k = min(min_k, k);
        }
    }

    cout << min_k << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1025 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -