import java.util.*;
import java.io.*;
class scheduling
//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 = in.nextInt();
int d = in.nextInt();
int m = in.nextInt();
Request[] array = new Request[m + 1];
for(int i = 1; i <= m; i++)
array[i] = new Request(i, in.nextInt());
in.close();
array[0] = new Request(-1, -1);
Arrays.sort(array);
names = new String[n + 1];
int result = binarySearch(n, d, m, array);
works(n, d, m, array, result);
for(int i = 1; i <= n; i++)
{
names[i] += "0 ";
names[i].trim();
}
// PrintWriter out = new PrintWriter(new File("scheduling.out"));
System.out.println(result);
// out.println(result);
for(int i = 1; i <= n; i++)
{
System.out.println(names[i]);
// 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 + 1];
for(int i = 1; i <= m; i++)
assign[i] = assign[i - 1] % mid + 1;
int[] lastSeen = new int[mid + 1];
for(int i = 1; i <= n; i++)
names[i] = "";
for(int i = 1; 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;
names[lastSeen[assign[i]]] += 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;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
158 ms |
12628 KB |
Execution failed because the return code was nonzero |
2 |
Runtime error |
161 ms |
12348 KB |
Execution failed because the return code was nonzero |
3 |
Runtime error |
160 ms |
12476 KB |
Execution failed because the return code was nonzero |
4 |
Runtime error |
160 ms |
12460 KB |
Execution failed because the return code was nonzero |
5 |
Runtime error |
160 ms |
12268 KB |
Execution failed because the return code was nonzero |
6 |
Runtime error |
161 ms |
12480 KB |
Execution failed because the return code was nonzero |
7 |
Runtime error |
163 ms |
12616 KB |
Execution failed because the return code was nonzero |
8 |
Runtime error |
164 ms |
12296 KB |
Execution failed because the return code was nonzero |
9 |
Runtime error |
165 ms |
12460 KB |
Execution failed because the return code was nonzero |
10 |
Runtime error |
165 ms |
12476 KB |
Execution failed because the return code was nonzero |
11 |
Runtime error |
159 ms |
12268 KB |
Execution failed because the return code was nonzero |
12 |
Runtime error |
160 ms |
12488 KB |
Execution failed because the return code was nonzero |
13 |
Runtime error |
161 ms |
12376 KB |
Execution failed because the return code was nonzero |
14 |
Runtime error |
160 ms |
12504 KB |
Execution failed because the return code was nonzero |
15 |
Runtime error |
159 ms |
12348 KB |
Execution failed because the return code was nonzero |
16 |
Runtime error |
160 ms |
12376 KB |
Execution failed because the return code was nonzero |
17 |
Runtime error |
160 ms |
12376 KB |
Execution failed because the return code was nonzero |
18 |
Runtime error |
162 ms |
12248 KB |
Execution failed because the return code was nonzero |
19 |
Runtime error |
160 ms |
12504 KB |
Execution failed because the return code was nonzero |
20 |
Runtime error |
160 ms |
12376 KB |
Execution failed because the return code was nonzero |