Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

Unit-time jobs are given as (deadline, profit): [(2, 100), (1, 19), (2, 27), (1, 25), (3, 15)]. Each job takes one time slot starting at time 1, and a job earns its profit only if it finishes by its deadline. What is the maximum total profit?

  1. A. 186
  2. B. 123
  3. C. 167
  4. D. 142

Correct answer: D. 142

Sort jobs by profit (largest first), and assign each job the latest free slot on or before its deadline. Taking the highest-profit jobs without checking deadlines, or ignoring the profit order, gives a different total.

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

Exams that ask this topic