# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666722 | omikron123 | Job Scheduling (CEOI12_jobs) | C++14 | 1090 ms | 10736 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.
// https://oj.uz/problem/view/CEOI12_jobs
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
// n,d<=1e5, m<=1e6
int n, d, m;
struct J {
int s, idx;
};
J jobs[1000005];
// return if x machine is enough
bool check(int x, bool print) {
// {deadline, idx}
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > q;
int j = 0; // job index
for (int i = 1; i <= n; i++) {
// enqueue job arrivals
for (; j < m && jobs[j].s == i; j++)
q.push({i + d, jobs[j].idx});
// consume jobs in queue
int cnt = 0;
while(!q.empty() && cnt < x) {
int deadline = q.top().first;
int idx = q.top().second;
q.pop();
if (deadline < i) // already expired
return false;
cnt++;
if (print)
printf("%d ", idx);
}
if (print)
printf("0\n");
}
return true;
}
inline bool cmp(J &a, J &b) {return a.s < b.s;}
inline int read() {
int r = 0;
bool start = false, neg = false;
while (true) {
char c = getchar();
if (!start && c != '-' && (c < '0' || c > '9')) continue;
start = true;
if (c == '-') neg = true;
else if (c >= '0' && c <= '9')
r = r * 10 + c - '0';
else
break;
}
return r;
}
int main() {
scanf("%d %d %d", &n, &d, &m);
for (int i = 0; i < m; i++) {
jobs[i].s = read();
jobs[i].idx = i+1;
}
sort(jobs, jobs+m, cmp);
int low = 1, high = m;
while (low < high) {
int mid = (low + high) / 2;
if (check(mid, false))
high = mid;
else
low = mid+1;
}
printf("%d\n", low);
check(low, true);
return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
answer is 2
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |