# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
675164 | wisePigOnTheMoon | Job Scheduling (CEOI12_jobs) | Java | 1095 ms | 39696 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.*;
import java.io.*;
public class jobs {
static class Job implements Comparable<Job> {
public int id, day;
public Job(int i, int d) {
id = i;
day = d;
}
public int compareTo(Job o) {
return this.day - o.day;
}
}
public static void main(String[] args) throws Exception {
Reader in = new Reader();
int days = in.nextInt();
int d = in.nextInt();
int m = in.nextInt();
Job[] jobs = new Job[m];
for (int i = 0; i < m; i++) {
int assign = in.nextInt();
jobs[i] = new Job(i + 1, assign);
}
Arrays.sort(jobs);
int l = 0;
int r = m;
while (l < r) {
int mid = (l + r)/2;
if (checkValid(mid, days, d, m, jobs)) {
r = mid;
} else {
l = mid + 1;
}
}
System.out.println(l);
printer(l, days, d, m, jobs);
}
public static boolean checkValid(int macs, int days, int d, int m, Job[] jobs) {
int i = 0;
int count = 1;
while (count <= days && i < m) {
int work = 0;
while (work < macs && i < m) {
if (jobs[i].day > count) {
break;
}
if (count > jobs[i].day + d) {
return false;
}
work++;
i++;
}
count++;
}
if (i < m) {
return false;
}
return true;
}
public static void printer(int macs, int days, int d, int m, Job[] jobs) {
int i = 0;
int count = 1;
while (count <= days && i < m) {
String ans = "";
int work = 0;
while (work < macs && i < m) {
if (jobs[i].day > count) {
break;
}
ans += jobs[i].id + " ";
work++;
i++;
}
count++;
System.out.println(ans + "0");
}
}
static class Reader //FastReader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |