# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
642385 | accidentac | Job Scheduling (CEOI12_jobs) | C++14 | 318 ms | 7724 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, d, m;
vector<array<int, 2>> jobs;
// return true if can use count no. of machines to handle all jobs
bool ok(int count) {
for (int i = 1, l = 0, r = 0; i <= n; i++) {
while (r < m && jobs[r][0] >= i) {
r++;
}
int cur = 0;
while (l < r && cur < count) {
if (i - jobs[l][0] > d) return false;
l++;
cur++;
if (l == m) return true;
}
}
return false;
}
int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
cin >> n >> d >> m;
jobs = vector<array<int, 2>>(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)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |