# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119481 | johu | Job Scheduling (CEOI12_jobs) | Java | 1089 ms | 54040 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 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
// Use a custom array for efficient memory usage
Pair[] a = new Pair[m + 1];
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= m; i++) {
a[i] = new Pair(Integer.parseInt(st.nextToken()), i);
}
// Sort array using Arrays.sort with a custom comparator
Arrays.sort(a, 1, m + 1);
int l = 0, r = m;
while (r - l > 1) {
int mid = (l + r) / 2;
int p = 1;
for (int i = 1; i <= n; i++) {
if (p > m || a[p].fr + d < i) {
break;
}
int cnt = 0;
while (cnt < mid && p <= m && a[p].fr <= i) {
cnt++;
p++;
}
}
if (p > m) {
r = mid;
} else {
l = mid;
}
}
System.out.println(r);
int p = 1;
// Use BufferedWriter for efficient output
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
for (int i = 1; i <= n; i++) {
int cnt = 0;
while (cnt < r && p <= m && a[p].fr <= i) {
bw.write(a[p].sc + " ");
cnt++;
p++;
}
bw.write("0\n");
}
bw.flush();
}
static class Pair implements Comparable<Pair> {
int fr, sc;
Pair(int fr, int sc) {
this.fr = fr;
this.sc = sc;
}
@Override
public int compareTo(Pair other) {
return Integer.compare(this.fr, other.fr);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |