Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
From tasks (value, cost) = (5, 4), (6, 2), (3, 1), (7, 5) you may choose any subset whose total cost is at most 7. What is the maximum number of tasks you can take (ignoring value)?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Taking cheapest tasks first maximises the count under a single budget by an exchange argument. Choosing by value (the trap) gives a different count.
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
- How many trailing zeros does 2^7 5^4 10 have in decimal?
- What is the number of unmatched '(' characters in the string "(()())(()" after the standard left-to-right matching?
- What is the largest number of distinct characters in any contiguous window of length 4 of "abcbdabca"?
- What is the sum of all positive divisors of 36?
- How many contiguous subarrays of [2, 4, 1, 3] have a sum in the inclusive range [4, 6]?
- How many distinct subsequences (including the empty string) does "aab" have?