# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119462 | johu | Job Scheduling (CEOI12_jobs) | Java | 1058 ms | 55468 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.
import java.io.*;
import java.util.*;
public class jobs {
static final int MAXN = 1000005;
static int n, m, d;
static Pair[] a = new Pair[MAXN];
static class Pair implements Comparable<Pair> {
int first, second;
Pair(int first, int second) {
this.first = first;
this.second = second;
}
@Override
public int compareTo(Pair other) {
return Integer.compare(this.first, other.first);
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
// Read n, d, m
n = Integer.parseInt(st.nextToken());
d = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
// Read the pairs
for (int i = 1; i <= m; i++) {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
int first = Integer.parseInt(st.nextToken());
a[i] = new Pair(first, i);
}
a[m + 1] = new Pair(Integer.MAX_VALUE, 0);
// Sort the pairs
Arrays.sort(a, 1, m + 1);
// Binary search for the minimum `r`
int l = 0, r = m;
while (r - l > 1) {
int mid = (l + r) / 2;
int p = 1;
boolean valid = true;
for (int i = 1; i <= n && valid; i++) {
if (a[p].first + d < i) {
valid = false;
break;
}
int cnt = 0;
while (cnt < mid && a[p].first <= i) {
cnt++;
p++;
}
}
if (p > m) {
r = mid;
} else {
l = mid;
}
}
// Print the result
System.out.println(r);
// Generate the schedule
int p = 1;
StringBuilder output = new StringBuilder();
for (int i = 1; i <= n; i++) {
int cnt = 0;
while (cnt < r && a[p].first <= i) {
cnt++;
output.append(a[p].second).append(" ");
p++;
}
output.append("0\n");
}
System.out.print(output);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |