TopcoderArchiveVisit Topcoder
TCO9 Jan 2019
TCO19 SRM 750

IdenticalBags

Problem statement, definition, constraints, and public examples.

Problem Statement

You are preparing for Halloween. You like to hand out bags of candy. In order to prevent arguments between the kids who get them, you want all bags to be identical.

You have a supply of various candy. Each element of candy is the number of pieces of a specific candy type. You want to create bags that will contain bagSize pieces of candy each. Compute and return the maximum number of identical bags you can make.

Definition

Class:
IdenticalBags
Method:
makeBags
Parameters:
long[], long
Returns:
long
Method signature:
long makeBags(long[] candy, long bagSize)
(be sure your method is public)

Constraints

  • candy will contain between 1 and 100 elements, inclusive.
  • Each element of candy will be between 1 and 10^18, inclusive.
  • bagSize will be between 1 and 10^18, inclusive.

Examples

  1. {10, 11, 12}
    3
    Returns: 10
    You can make 10 identical bags, each containing one candy of each type.
  2. {10, 11, 12, 1, 2, 3}
    3
    Returns: 10
    We have a few more candy types than in Example #0, but the optimal solution remained the same.
  3. {100}
    7
    Returns: 14
    This time you can make (100 div 7) bags, each containing 7 candies of the only type you have.
  4. {10000000000, 20000000000, 30000000000}
    6
    Returns: 10000000000
    Watch out for integer overflow.
Back to all problems