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?
- A. 19
- B. 3
- C. 27
- 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.
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
- Items as (weight, value) are [(10, 60), (20, 100), (30, 120)]. You may take any FRACTION of an item. The capacity is 50. What is the…
- Five jobs (processing time, due date) are [(4, 9), (2, 6), (6, 12), (3, 7), (5, 10)]. They run one at a time with no preemption, starting…
- Stalls are at positions [1, 2, 8, 4, 9, 15, 17] on a line. You must place C = 4 cows in distinct stalls to maximise the MINIMUM distance…
- Books have page counts [12, 34, 67, 90, 25, 40, 18] in this fixed order. They are split among K = 3 students so that each student receives…
- Koko has banana piles [3, 6, 7, 11] and H = 8 hours. Each hour she eats up to k bananas from ONE pile (if a pile has fewer, she finishes…
- For the array [19, 4, 33, 12, 7, 29], find the smallest positive integer d such that the sum of ceil(x / d) over all elements is at most…