Submission #1119481

#TimeUsernameProblemLanguageResultExecution timeMemory
1119481johuJob Scheduling (CEOI12_jobs)Java
60 / 100
1089 ms54040 KiB
import java.io.*; import java.util.*; public class jobs { 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()); int d = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); // Use a custom array for efficient memory usage Pair[] a = new Pair[m + 1]; st = new StringTokenizer(br.readLine()); for (int i = 1; i <= m; i++) { a[i] = new Pair(Integer.parseInt(st.nextToken()), i); } // Sort array using Arrays.sort with a custom comparator Arrays.sort(a, 1, m + 1); int l = 0, r = m; while (r - l > 1) { int mid = (l + r) / 2; int p = 1; for (int i = 1; i <= n; i++) { if (p > m || a[p].fr + d < i) { break; } int cnt = 0; while (cnt < mid && p <= m && a[p].fr <= i) { cnt++; p++; } } if (p > m) { r = mid; } else { l = mid; } } System.out.println(r); int p = 1; // Use BufferedWriter for efficient output BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); for (int i = 1; i <= n; i++) { int cnt = 0; while (cnt < r && p <= m && a[p].fr <= i) { bw.write(a[p].sc + " "); cnt++; p++; } bw.write("0\n"); } bw.flush(); } 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); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...