Cargo Spaceship Loading
Time limit1sMemory limit256 MB
You pack items weighing powers of three to maximize total value within each capacity and print the count per dimension.
Problem
Juliet is reading a science fiction novel. In one chapter the main character has to get the most out of a cargo spaceship's capacity. The cargo consists of items shaped like a -dimensional mesh whose size is 3 nodes along every dimension. Each node of the mesh holds one ball, and all balls weigh the same. The connections between balls are so light that their weight is negligible next to the weight of a ball, so the weight of an item is decided only by the number of its nodes. The value of an item is the number of nodes plus the number of connections.
A -dimensional item has nodes, and there is one connection between every two nodes that are neighbours along a single axis.
A spaceship has a limit on the weight it can carry. Load items so that the total weight stays within the limit and the total value is as large as possible. The supply of items is unlimited for every dimension. Exactly one loading reaches the largest total value.
Input
The first line contains the number of test cases . is a positive integer.
Each of the next lines contains one integer , the cargo capacity of the ship. ()
Output
For each test case, print on one line, separated by single spaces. is the number of items of dimension to load for the largest total value, and the count of the highest dimension, , is greater than 0.