Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Items (value, weight) = (60, 10), (100, 20), (120, 30) can be split fractionally. With capacity 50, what is the maximum total value?
- A. 220
- B. 241
- C. 200
- D. 240
Correct answer: D. 240
Fractional knapsack is solved greedily by value-to-weight ratio; the first two items fill 30 units with value 160 and the rest of the capacity takes two-thirds of the third item's value 80 or the answer of 240.
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 windows of size 3 in [1, 2, 2, 3, 4, 4, 5] have every pair of adjacent elements inside the window different?
- How many contiguous subarrays of [3, 1, 2, 1, 4] have their minimum equal to their first element?
- How many entries of [1, 6, 8, 12, 16, 33, 64, 0] are powers of two (with 1 counted)?
- What is the length of the longest contiguous subarray of [0, 1, 0, 0, 1, 1, 0, 1] containing equal numbers of 0s and 1s?
- How many ordered pairs of distinct positions (i, j) in [2, 3, 4, 6, 12] satisfy a[j] divisible by a[i]?
- In how many ways can 12 be written as a sum of distinct positive odd integers (order does not matter)?