Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

You may partition the multiset [3, 1, 4, 1, 5, 9, 2, 6] into as many GROUPS as possible, where every group must have sum at least 7 and leftover numbers can be discarded. Groups are formed from numbers (each number used at most once). What is the maximum number of groups?

  1. A. 3
  2. B. 4
  3. C. 6
  4. D. 2

Correct answer: A. 3

Sort, then build each group from the smallest numbers still available until its sum reaches K; closing a group as early as possible leaves more room for the rest. Taking the largest numbers first, or the total sum over K, overcounts groups.

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

Exams that ask this topic