Data Structures & AlgorithmsVery hardICPC regional · TCS NQT

Items as (weight, value) are [(4, 6), (2, 3), (5, 9), (3, 4), (6, 10), (1, 1)]. You must take EXACTLY 3 different items with total weight at most 10. What is the maximum total value?

  1. A. 16
  2. B. 19
  3. C. 15
  4. D. 25

Correct answer: A. 16

Knapsack with a count dimension: {(4,6), (5,9), (1,1)} weighs exactly 10 and is worth 16, which no other legal triple beats. Taking the top three values ignoring weight gives 25, the two most valuable items (19) already weigh 11, and reading the limit as < 10 gives 15.

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

Exams that ask this topic