import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class jobSheduling {
// 7 mins planning
static int N,D,M;
static Integer [][] requests;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer s = new StringTokenizer(br.readLine());
N = Integer.parseInt(s.nextToken());
D = Integer.parseInt(s.nextToken());
M = Integer.parseInt(s.nextToken());
requests = new Integer [M][2]; // day, orgInd
s = new StringTokenizer(br.readLine());
for (int i = 0; i < M; i++) {
requests[i][0] = Integer.parseInt(s.nextToken());
requests[i][1] = i+1;
}
Arrays.sort(requests, (integers, t1) -> integers[0] - t1[0]);
int a = 1, b = M;
while (a != b) {
int mid = (a+b)/2;
if (works(mid)) b=mid;
else a = mid+1;
}
out.println(b);
int [] lastDays = new int [b];
HashMap<Integer,HashSet<Integer>> requestsAtEachDay = new HashMap<>();
for (int i = 0, currMach = 0; i < M; i++,currMach++) {
int currDay = requests[i][0];
if (currMach == b) currMach = 0;
int nextMachDay = lastDays[currMach]+1;
lastDays[currMach] = Math.max(nextMachDay, currDay);
int machDay = Math.max(nextMachDay, currDay);
if (!requestsAtEachDay.containsKey(machDay)) requestsAtEachDay.put(machDay,new HashSet<>());
requestsAtEachDay.get(machDay).add(requests[i][1]);
}
for (int i = 1; i <= N; i++) {
if (requestsAtEachDay.containsKey(i)) {
for (int num : requestsAtEachDay.get(i)) {
out.print(num+" ");
}
}
out.println(0);
}
out.close();
}
static boolean works (int numMachines) {
int [] lastDays = new int [numMachines];
int maxD = 0;
for (int i = 0, currMach = 0; i < M; i++,currMach++) {
int currDay = requests[i][0];
if (currMach == numMachines) currMach = 0;
int nextMachDay = lastDays[currMach]+1;
if (nextMachDay > currDay) {
maxD = Math.max(maxD,nextMachDay-currDay);
lastDays[currMach] = nextMachDay;
}
else {
lastDays[currMach] = currDay;
}
}
return maxD <= D;
}
}
Compilation message
jobs.java:7: error: class jobSheduling is public, should be declared in a file named jobSheduling.java
public class jobSheduling {
^
1 error