Submission #354454

# Submission time Handle Problem Language Result Execution time Memory
354454 2021-01-22T02:06:02 Z superadi04 Job Scheduling (CEOI12_jobs) Java 11
Compilation error
0 ms 0 KB
import java.io.*;
import java.util.*;

public class JobScheduling {
    static int n, d, m;
    static Pair[] requests;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        n = Integer.parseInt(st.nextToken());
        d = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());
        requests = new Pair[m];
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < m; i++) {
            requests[i] = new Pair(Integer.parseInt(st.nextToken()), i + 1);
        }
        Arrays.sort(requests, (r1, r2) -> r1.a - r2.a);

        // Binary search on the answer
        int lo = 0, hi = n;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (check(mid)) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }

        // Print answer
        System.out.println(lo);
        int days = 0;
        for (int i = 0; i < m; i += lo) {
            days++;
            int j = i;
            while (j < m && j < i + lo) {
                System.out.print(requests[j].b + " ");
                j++;
            }
            System.out.println(0);
        }

        // Print out the remaining zeroes
        while (days < n) {
            days++;
            System.out.println(0);
        }
    }


    static boolean check(int delay) {
        int days = 0;
        for (int i = 0; i < m; i += delay) {
            days++;
            int j = i;
            while (j < m && j < i + delay) {
                if (requests[j].a + d >= days) {
                    j++;
                } else {
                    return false;
                }
            }
        }
        return days <= n;
    }

    static class Pair {
        int a, b;

        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
    }
}

Compilation message

jobs.java:4: error: class JobScheduling is public, should be declared in a file named JobScheduling.java
public class JobScheduling {
       ^
1 error