import java.io.*;
import java.util.*;
public class JobScheduling {
static int n;
static int d;
static int m;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter (System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
d = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
int[][] arr = new int[m][2];
st = new StringTokenizer(br.readLine());
for (int i=0; i<m; i++){
arr[i] = new int[] {Integer.parseInt(st.nextToken()), i+1};
}
Arrays.sort(arr, (a, b) -> a[0]-b[0]);
int low = 1;
int high = m;
while (low < high){
int mid = (low + high)/2;
if (check(mid, arr)){
high = mid;
}else{
low = mid+1;
}
}
out.println(low);
ArrayList<Integer>[] eachDay = new ArrayList[n+1];
for (int i=0; i<=n; i++){
eachDay[i] = new ArrayList<>();
}
int[] end = new int[low];
for (int i=0, id = 0; i<m; i++, id++){
if (id == low){
id = 0;
}
int requestDay = arr[i][0];
int canDo = end[id]+1;
end[id] = Math.max(requestDay, canDo);
eachDay[end[id]].add(arr[i][1]);
}
for (int i=1; i<=n; i++){
if (eachDay[i] != null){
for (int j : eachDay[i]){
out.print(j + " ");
}
}
out.print("0");
out.println();
}
out.close();
}
public static boolean check(int mid, int[][] arr){
int[] end = new int[mid];
int index = 0;
int maxD = 0;
for (int i=0; i<m; i++){
if (index == mid){
index = 0;
}
if (end[index]+1 > arr[i][0]){
maxD = Math.max(maxD, end[index]+1-arr[i][0]);
end[index]++;
}else{
end[index] = arr[i][0];
}
index++;
}
return maxD <= d;
}
}
Compilation message
jobs.java:4: error: class JobScheduling is public, should be declared in a file named JobScheduling.java
public class JobScheduling {
^
Note: jobs.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error