All submissions for this problem are available.
Recycling plastic bags requires that the plastic be separated by color into one of three categories: brown bag, green bag, and clear bag. In this problem you will be given three recycling bins, each containing a specified number of brown, green and clear bags. In order to be recycled, the bags will need to be moved so that each bin contains bags of only one color.
The problem is to minimize the number of bottles that are moved. You may assume that the only problem is to minimize the number of movements between boxes.
For the purposes of this problem, each bin has infinite capacity and the only constraint is moving the bottles so that each bin contains bags of a single color. The total number of bags will never exceed 2^31.
The input consists of a series of lines with each line containing 9 integers. The first three integers on a line represent the number of brown, green, and clear bags (respectively) in bin number 1, the second three represent the number of brown, green and clear bags (respectively) in bin number 2, and the last three integers represent the number of brown, green, and clear bags (respectively) in bin number 3. For example, the line 10 15 20 30 12 8 15 8 31
indicates that there are 20 clear bags in bin 1, 12 green bags in bin 2, and 15 brown bags in bin 3.
Integers on a line will be separated by one or more spaces. Your program should process all lines in the input file.
For each line of input there will be one line of output indicating what color bottles go in what bin to minimize the number of bag movements. You should also print the minimum number of bag movements.
The output should consist of a string of the three upper case characters 'G', 'B', 'C' (representing the colors green, brown, and clear) representing the color associated with each bin.
The first character of the string represents the color associated with the first bin, the second character of the string represents the color associated with the second bin, and the third character represents the color associated with the third bin.
The integer indicating the minimum number of bag movements should follow the string.
If more than one order of brown, green, and clear bins yields the minimum number of movements then the alphabetically first string representing a minimal configuration should be printed.
Input: 1 2 3 4 5 6 7 8 9 5 10 5 20 10 5 10 20 10 Output: BCG 30 CBG 50
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.