#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1025 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1022 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |