Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Weighted jobs (start, end, weight) are [(1, 3, 5), (2, 5, 6), (4, 6, 5), (6, 7, 4), (5, 8, 11), (8, 9, 2)]. Two jobs are compatible when one ends at or before the other starts. What is the maximum total weight of a compatible set?

  1. A. 19
  2. B. 3
  3. C. 27
  4. D. 14

Correct answer: A. 19

Sort by end time and let dp[i] = max(dp[i−1], w_i + dp[last compatible job]); the last compatible job is found by binary search. Maximising the count of jobs (ignoring weights) or greedily taking the heaviest job first can both lose weight.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic