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?
- A. 186
- B. 123
- C. 167
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Jobs as (processing time, weight) are [(3, 2), (2, 1), (4, 4), (1, 3)]. They run one at a time with no idle time, and the cost is the sum…
- Tasks AAABBBCCD (each letter is a task, one unit of time each) run on a single CPU. Two identical tasks must be separated by at least n =…
- A set of symbols has frequencies [5, 9, 12, 13, 16, 45]. Huffman coding repeatedly merges the two smallest weights, and each merge costs…
- A circular route has gas stations with gas = [1, 2, 3, 4, 5, 2] and travel cost to the next station = [3, 4, 5, 1, 2, 3]. You start with…
- A garden of length 5 has taps at positions 0 to 5. Tap i waters the interval [i − ranges[i], i + ranges[i]] where ranges = [3, 4, 1, 1, 0…
- From the number 1432219 you must delete exactly 3 digits (the remaining digits keep their order). What is the smallest number you can…