# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
343976 | 2021-01-05T01:23:41 Z | vijay | Job Scheduling (CEOI12_jobs) | Java 11 | 0 ms | 0 KB |
import java.io.*; import java.util.*; public class jobs { static int N, D, M; static Pair[] requests; public static void main(String[] args) throws IOException, FileNotFoundException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("job.out"))); N = in.nextInt(); D = in.nextInt(); M = in.nextInt(); requests = new Pair[M]; for(int i = 0; i < M; i++){ requests[i] = new Pair(in.nextInt(), i + 1); } Arrays.sort(requests); int a = 1; int b = 1000000; while(a != b){ int mid = (a + b)/2; if(works(mid)){ b = mid; } else { a = mid + 1; } } String[] returns = new String[N]; int machineIdx = 0; int[] lastTask = new int[a]; for(int i = 0; i < M; i++){ lastTask[machineIdx] = Math.max(lastTask[machineIdx] + 1, requests[i].a); int idx = lastTask[machineIdx] - 1; if(returns[idx] == null){ returns[idx] = String.valueOf(requests[i].b); } else { returns[idx] += " " + requests[i].b; } machineIdx++; machineIdx %= a; } System.out.println(a); for(int i = 0; i < N; i++){ if(returns[i] != null){ System.out.println(returns[i] + " 0"); } else { System.out.println("0"); } } } public static boolean works(int machines){ int[] lastTask = new int[machines]; int machineIdx = 0; for(int i = 0; i < M; i++){ lastTask[machineIdx] = Math.max(lastTask[machineIdx] + 1, requests[i].a); if(lastTask[machineIdx] - requests[i].a > D){ return false; } machineIdx++; machineIdx %= machines; } return true; } static class Pair implements Comparable<Pair>{ int a, b; public Pair(int a, int b){ this.a = a; this.b = b; } public int compareTo(Pair p){ return a - p.a; } } }