# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642400 | accidentac | Job Scheduling (CEOI12_jobs) | C++14 | 330 ms | 7328 KiB |
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;
// return true if can use count no. of machines to handle all jobs
bool ok(int count, int n, int d, int m, vector<array<int, 2>>& jobs) {
for (int i = 1, start = 0, end = 0; i <= n; i++) {
while (end < m && jobs[end][0] <= i) {
end++;
}
int cur = 0;
while (start < end && cur < count) {
if (i - jobs[start][0] > d) return false;
start++;
cur++;
if (start == m) return true;
}
}
return false;
}
int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int n, d, m;
cin >> n >> d >> m;
vector<array<int, 2>> jobs(m);
for (int i = 0; i < m; i++) {
cin >> jobs[i][0];
jobs[i][1] = i + 1;
}
sort(jobs.begin(), jobs.end());
int lo = 1, hi = m, ans = m;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (ok(mid, n, d, m, jobs)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |