Candy Boxes
Time limit2sMemory limit1024 MB
Given N and a candy box of size a x b x c, find a large box whose three sides sum to at most N and that holds the most candy boxes in the same orientation.
- Level
Medium6 of 10
- Topics
- Math, Brute force
- Solved
- No attempts yet
Statement
Petya lives in city P, where a candy factory makes very tasty candies. Petya plans to travel by train to city M to visit his friend Vasya. He wants to bring as many boxes of candy as possible as a gift.
Each candy box has size cm, where is the length, is the width, and is the height. Petya uses one large box shaped like a rectangular parallelepiped. All candy boxes must fit inside it. Each candy box must keep its original orientation, and all of them must face the same direction. Petya may choose any size for the large box, but the sum of its three dimensions cannot exceed cm under the railway rules.
Write a program that, given , , , and , finds the size of the box Petya should use so that it holds the maximum number of candy boxes.
Input
The first line contains four integers separated by spaces: , , , and ().
Output
Print three numbers: the length, width, and height of the box Petya should choose, so that the maximum number of candy boxes fits. If several answers are possible, print any of them.
Hint
In the first example, the best choice is a cm box. Three candy boxes fit along the length, two along the width, and one along the height.
In the second example, at least two candy boxes require a box of at least cm, whose dimensions sum to 15. Such a box holds at most one candy box. The box is also a valid answer, even though it is not the smallest one.