This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
bool canDivide(vector<int>& times, int maxDiff, int A, int B, int N) {
int groups = 0, i = 0;
while (i < N) {
int start_time = times[i];
int members = 0;
while (i < N && members < B && times[i] - start_time <= maxDiff) {
i++;
members++;
}
if (members < A) return false; // Cannot form a valid group
groups++;
}
return true;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
vector<int> times(N);
for (int& time : times) cin >> time;
sort(times.begin(), times.end());
int low = 0, high = times.back() - times.front(), ans = high;
while (low <= high) {
int mid = low + (high - low) / 2;
if (canDivide(times, mid, A, B, N)) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |