Connection Status:
Competition Arena > SchoolAssembly
TCO04 Round 2 · 2004-09-07 · by schveiguy · Brute Force, Greedy
Class Name: SchoolAssembly
Return Type: int
Method Name: getBeans
Arg Types: (int, int)
Problem Statement

Problem Statement

You are a director of a school, having an assembly for your kids. The assembly is on the topic of consistency, and as a demonstration, you want to hand out a number of jelly beans to each kid, and have all the jelly beans that an individual kid receives be the same color (one kid's color may be different than another kid's color). At the store, each bag of jelly beans contains exactly 20 beans, and each bean can be one of 5 colors. The bags are opaque, so you cannot determine ahead of time exactly how many of each color bean are in each bag (a bag could have any combination of the 5 colors, including 20 of one color). Given an int kids (the number of children) and an int quantity (the number of beans you want to give each kid), return how many bags of jelly beans you must buy to ensure that you have enough jelly beans to give each individual kid quantity same-colored beans.

Constraints

  • kids will be between 1 and 1000, inclusive.
  • quantity will be between 2 and 25, inclusive.
Examples
0)
1
5
Returns: 2

Only one kid to buy for. Since the first bag you buy could contain 4 of each color, you must buy a second bag to ensure the child has 5 of the same color.

1)
1
2
Returns: 1
2)
5
5
Returns: 3

If we buy 2 bags, we will be able to give 4 of the children 5 beans. However, we could be left with 4 beans of each color, requiring the third bag.

3)
223
15
Returns: 171
4)
1000
25
Returns: 1255

Submissions are judged against all 74 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SchoolAssembly with a public method int getBeans(int kids, int quantity) · 74 test cases · 2 s / 256 MB per case

Submitting as anonymous