Submission #474786

# Submission time Handle Problem Language Result Execution time Memory
474786 2021-09-19T17:41:52 Z sbane13 Job Scheduling (CEOI12_jobs) Java 11
0 / 100
1000 ms 43180 KB
import java.util.*;

public class jobs {

    static int n, d, m;

    static ArrayList<Job> jobs = new ArrayList<>();

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        n = in.nextInt(); d = in.nextInt(); m = in.nextInt();


        for(int i = 0; i < m; i++){
            jobs.add(new Job(in.nextInt(), i));
        }

        Collections.sort(jobs);

        int s = 1, e = 1000000000;

        while (s != e) {
            int mid = (s+e)/2;
            if (is_pos(mid)) {
                e = mid;
            } else {
                s = mid + 1;
            }
        }

        int ans = s;

        System.out.println(ans);

        int i = 0, j = 0;

        for (int day = 1; day <= n; day++) {
            while (j < jobs.size() && j - i + 1 <= ans && jobs.get(j).job <= day) {
                j++;
            }
            while (i < j) {
                System.out.print(jobs.get(i).day + 1 + " ");
                i++;
            }

            System.out.println("0");

        }
    }

    static boolean is_pos(int mid) {
        int i = 0, j = 0;

        for (int day = 1; day <= n; day++) {
            while (j < jobs.size() && j - i + 1 <= mid && jobs.get(j).job <= day) {
                j++;
            }
            while (i < j) {
                if (day - jobs.get(i).job > d) return false;
                i++;
            }
        }

        return i >= n;
    }

    static class Job implements Comparable<Job>{
        int job, day;

        public Job(int job, int day) {
            this.job = job;
            this.day = day;
        }

        public int compareTo(Job o) {
            return this.job-o.job;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 23028 KB Time limit exceeded
2 Execution timed out 1092 ms 22156 KB Time limit exceeded
3 Execution timed out 1100 ms 22244 KB Time limit exceeded
4 Execution timed out 1091 ms 22324 KB Time limit exceeded
5 Execution timed out 1080 ms 22136 KB Time limit exceeded
6 Execution timed out 1094 ms 22164 KB Time limit exceeded
7 Execution timed out 1092 ms 22212 KB Time limit exceeded
8 Execution timed out 1094 ms 22308 KB Time limit exceeded
9 Execution timed out 1089 ms 22396 KB Time limit exceeded
10 Execution timed out 1085 ms 22296 KB Time limit exceeded
11 Execution timed out 1091 ms 22264 KB Time limit exceeded
12 Execution timed out 1090 ms 26984 KB Time limit exceeded
13 Execution timed out 1089 ms 31952 KB Time limit exceeded
14 Execution timed out 1043 ms 39488 KB Time limit exceeded
15 Execution timed out 1086 ms 39924 KB Time limit exceeded
16 Execution timed out 1094 ms 39596 KB Time limit exceeded
17 Execution timed out 1090 ms 40464 KB Time limit exceeded
18 Execution timed out 1092 ms 40248 KB Time limit exceeded
19 Execution timed out 1090 ms 43180 KB Time limit exceeded
20 Execution timed out 1086 ms 41000 KB Time limit exceeded