Submission #1119462

#TimeUsernameProblemLanguageResultExecution timeMemory
1119462johuJob Scheduling (CEOI12_jobs)Java
55 / 100
1058 ms55468 KiB
import java.io.*; import java.util.*; public class jobs { static final int MAXN = 1000005; static int n, m, d; static Pair[] a = new Pair[MAXN]; static class Pair implements Comparable<Pair> { int first, second; Pair(int first, int second) { this.first = first; this.second = second; } @Override public int compareTo(Pair other) { return Integer.compare(this.first, other.first); } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); // Read n, d, m n = Integer.parseInt(st.nextToken()); d = Integer.parseInt(st.nextToken()); m = Integer.parseInt(st.nextToken()); // Read the pairs for (int i = 1; i <= m; i++) { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } int first = Integer.parseInt(st.nextToken()); a[i] = new Pair(first, i); } a[m + 1] = new Pair(Integer.MAX_VALUE, 0); // Sort the pairs Arrays.sort(a, 1, m + 1); // Binary search for the minimum `r` int l = 0, r = m; while (r - l > 1) { int mid = (l + r) / 2; int p = 1; boolean valid = true; for (int i = 1; i <= n && valid; i++) { if (a[p].first + d < i) { valid = false; break; } int cnt = 0; while (cnt < mid && a[p].first <= i) { cnt++; p++; } } if (p > m) { r = mid; } else { l = mid; } } // Print the result System.out.println(r); // Generate the schedule int p = 1; StringBuilder output = new StringBuilder(); for (int i = 1; i <= n; i++) { int cnt = 0; while (cnt < r && a[p].first <= i) { cnt++; output.append(a[p].second).append(" "); p++; } output.append("0\n"); } System.out.print(output); } }
#Verdict Execution timeMemoryGrader output
Fetching results...