Submission #1119467

#TimeUsernameProblemLanguageResultExecution timeMemory
1119467johuJob Scheduling (CEOI12_jobs)Java
0 / 100
70 ms12028 KiB
import java.io.*; import java.util.*; public class jobs { static class Pair implements Comparable<Pair> { int fr, sc; Pair(int fr, int sc) { this.fr = fr; this.sc = sc; } @Override public int compareTo(Pair other) { return Integer.compare(this.fr, other.fr); } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); // Number of days int d = Integer.parseInt(st.nextToken()); // Delay allowed int m = Integer.parseInt(st.nextToken()); // Number of events Pair[] a = new Pair[m + 2]; for (int i = 1; i <= m; i++) { int fr = Integer.parseInt(st.nextToken()); a[i] = new Pair(fr, i); // Store event and its index } a[m + 1] = new Pair((int) 1e9, 0); // Add a dummy pair for boundary handling Arrays.sort(a, 1, m + 1); // Sort by the `fr` value int l = 0, r = m; // Binary search to find the minimum value of `r` while (r - l > 1) { int mid = (l + r) / 2; int p = 1; boolean valid = true; for (int i = 1; i <= n; i++) { if (p > m || a[p].fr + d < i) { valid = false; break; } int cnt = 0; while (cnt < mid && p <= m && a[p].fr <= i) { cnt++; p++; } } if (valid && p > m) { r = mid; // Valid with this `mid` } else { l = mid; // Not valid, increase `l` } } // Print the result System.out.println(r); int p = 1; StringBuilder sb = new StringBuilder(); for (int i = 1; i <= n; i++) { int cnt = 0; while (cnt < r && p <= m && a[p].fr <= i) { sb.append(a[p].sc).append(" "); cnt++; p++; } sb.append(0).append("\n"); } System.out.print(sb); } }
#Verdict Execution timeMemoryGrader output
Fetching results...