Problem B
Closing the Loop
Given a bag full of rope segments, you will build the
longest loop of rope while alternating colors. The bag contains
Note that pieces of string that have length 1, if used in making the cycle, might get reduced to just a pair of knots of total length 0. This is allowed, and each such piece counts as having been used.
Input
The first line of input gives the number of cases,
-
One line containing the value
, the number of rope segments in the bag. -
One line containing a space separated list of
values. Each value indicates the segment length in centimeters followed by the letter or to indicate the segment color.
You may assume that
Output
For each test case, output one line containing "Case
#
Sample Input 1 | Sample Output 1 |
---|---|
4 1 5B 4 6R 1B 7R 3B 7 5B 4R 3R 2R 5R 4R 3R 2 20B 20R |
Case #1: 0 Case #2: 13 Case #3: 8 Case #4: 38 |