TopcoderArchiveVisit Topcoder
SRM25 May 2011
SRM 524

ShippingCubes

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
ShippingCubes
Method:
minimalCost
Parameters:
int
Returns:
int
Method signature:
int minimalCost(int N)
(be sure your method is public)

Constraints

  • N will be between 1 and 200, inclusive.

Examples

  1. 1
    Returns: 3
    The only way is to use a box with dimensions 1 x 1 x 1.
  2. 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.
  3. 7
    Returns: 9
  4. 200
    Returns: 18
Back to all problems