import java.util.*;
import java.io.*;
class jobs
//public class scheduling
{
static String[] names;
public static void main(String[] args) throws FileNotFoundException
{
Scanner in = new Scanner(new File("scheduling.in"));
Scanner in = new Scanner(System.in);
int n = 10;
int n = in.nextInt();
int d = in.nextInt();
int m = in.nextInt();
Request[] array = new Request[m];
for(int i = 0; i < m; i++)
array[i] = new Request(i + 1, in.nextInt());
in.close();
Arrays.sort(array);
names = new String[n];
//int result = 0;
int result = binarySearch(n, d, m, array);
//works(n, d, m, array, result);
PrintWriter out = new PrintWriter(new File("scheduling.out"));
//System.out.println(result);
out.println(result);
for(int i = 0; i < n; i++)
{
//System.out.println(names[i] + "0");
out.println(names[i]);
}
out.close();
}
static int binarySearch(int n, int d, int m, Request[] array)
{
int a = 1;
int b = m;
while(a != b)
{
int mid = (a + b) / 2;
if(works(n, d, m, array, mid))
b = mid;
else
a = mid + 1;
}
return a;
}
static boolean works(int n, int d, int m, Request[] array, int mid)
{
int[] assign = new int[m];
for(int i = 1; i < m; i++)
assign[i] = (assign[i - 1] + 1) % mid;
int[] lastSeen = new int[mid];
for(int i = 0; i < n; i++)
names[i] = "";
for(int i = 0; i < m; i++)
{
if(lastSeen[assign[i]] + 1 - array[i].day > d)
return false;
if(array[i].day - lastSeen[assign[i]] > 0)
lastSeen[assign[i]] = array[i].day;
else
lastSeen[assign[i]] = lastSeen[assign[i]] + 1;
if(lastSeen[assign[i]] - 1 > n)
return false;
names[lastSeen[assign[i]] - 1] += array[i].index + " ";
}
return true;
}
static class Request implements Comparable<Request>
{
int index, day;
Request(int index, int day)
{
this.index = index;
this.day = day;
}
public int compareTo(Request other)
{
return this.day - other.day;
}
public String toString()
{
return index + ":" + day;
}
}
}
Compilation message
jobs.java:11: error: variable in is already defined in method main(String[])
Scanner in = new Scanner(System.in);
^
jobs.java:13: error: variable n is already defined in method main(String[])
int n = in.nextInt();
^
2 errors