import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class jobs {
// 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];
s = new StringTokenizer(br.readLine());
for (int i = 0; i < M; i++) {
requests[i] = Integer.parseInt(s.nextToken());
}
Arrays.sort(requests);
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);
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];
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;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
313 ms |
15372 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
325 ms |
15296 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
304 ms |
15476 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
305 ms |
15200 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
332 ms |
15576 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
301 ms |
15388 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
309 ms |
15204 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
297 ms |
15200 KB |
Unexpected end of file - int32 expected |
9 |
Execution timed out |
1080 ms |
15712 KB |
Time limit exceeded |
10 |
Execution timed out |
1068 ms |
15728 KB |
Time limit exceeded |
11 |
Execution timed out |
1091 ms |
18128 KB |
Time limit exceeded |
12 |
Execution timed out |
1090 ms |
20640 KB |
Time limit exceeded |
13 |
Execution timed out |
1082 ms |
21964 KB |
Time limit exceeded |
14 |
Execution timed out |
1096 ms |
28000 KB |
Time limit exceeded |
15 |
Execution timed out |
1095 ms |
27724 KB |
Time limit exceeded |
16 |
Execution timed out |
1092 ms |
35636 KB |
Time limit exceeded |
17 |
Execution timed out |
1089 ms |
37764 KB |
Time limit exceeded |
18 |
Execution timed out |
1101 ms |
39256 KB |
Time limit exceeded |
19 |
Execution timed out |
1088 ms |
38788 KB |
Time limit exceeded |
20 |
Execution timed out |
1088 ms |
37548 KB |
Time limit exceeded |