Packing Balls
InterviewTime limit2sMemory limit512 MB
Given counts of red, green, and blue balls, pack them all into minimum boxes where each box holds 1 to 3 balls of one color or three distinct colors.
- Level
Medium6 of 10
- Topics
- Greedy, Math, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
You have red balls, green balls, and blue balls.
Pack all of them into boxes. One box holds 1, 2, or 3 balls.
The balls inside a single box must be all the same color or all different colors.
Write a program that finds the minimum number of boxes needed to pack every ball.
Input
The first line contains , , and , separated by spaces. ()
Output
Print the minimum number of boxes on the first line.
Note
The first example can be packed as (red, green, blue), (red, green), (red, red), (blue, blue, blue).
The second example is packed as (red, green, blue), (green, green, green), (green, green, green).