The Fortified Forest |
Once upon a time, in a faraway land, there lived a king. This king owned a small collection of rare and valuable trees, which had been gathered by his ancestors on their travels. To protect his trees from thieves, the king ordered that a high fence be built around them. His wizard was put in charge of the operation.
Alas, the wizard quickly noticed that the only suitable material available to
build the fence was the wood from the trees
themselves. In other words, it was necessary to cut down some trees in
order to build a fence around the remaining trees.
Of course, to prevent his head from being chopped off, the wizard wanted to
minimize the value of the trees that had to
be cut. The wizard went to his tower and stayed there until he had found the
best possible solution to the problem. The
fence was then built and everyone lived happily ever after.
You are to write a program that solves the problem the wizard faced.
The input ends with an empty test case (n = 0).
Display, as shown below, the test case numbers (1, 2, ...), the identity of each tree to be cut, and the length of the excess fencing (accurate to two fractional digits).
Display a blank line between test cases.
6 0 0 8 3 1 4 3 2 2 1 7 1 4 1 2 3 3 5 4 6 2 3 9 8 3 3 0 10 2 5 5 20 25 7 -3 30 32 0
Forest 1 Cut these trees: 2 4 5 Extra wood: 3.16 Forest 2 Cut these trees: 2 Extra wood: 15.00