이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |