Connection Status:
Competition Arena > ShippingCubes
SRM 524 · 2011-05-25 · by cgy4ever · Simple Search, Iteration
Class Name: ShippingCubes
Return Type: int
Method Name: minimalCost
Arg Types: (int)
Problem Statement

Problem Statement

You want to ship N cubes abroad. The size of each cube is 1 x 1 x 1. You can only ship the cubes by filling them into a single cuboid box. The cost of shipping a cuboid box with dimensions a x b x c is equal to (a+b+c).

You can't leave any empty space in the box, because the cubes would shift and get damaged during the transfer.

You are given an int N. Return the minimal cost of shipping N cubes.

Constraints

  • N will be between 1 and 200, inclusive.
Examples
0)
1
Returns: 3

The only way is to use a box with dimensions 1 x 1 x 1.

1)
6
Returns: 6

This time one optimal solution is to send a box with dimensions 1 x 2 x 3. The cost of sending this box is 1+2+3 = 6. Any other option is at least as expensive as this one. For example, sending a box with dimensions 6 x 1 x 1 has the cost 6+1+1 = 8.

2)
7
Returns: 9
3)
200
Returns: 18
4)
58
Returns: 32

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

Coding Area

Language: C++17 · define a public class ShippingCubes with a public method int minimalCost(int N) · 78 test cases · 2 s / 256 MB per case

Submitting as anonymous