So I've tested it against a few samples I have in mind, including the included sample I/Os.Originally, cost = Bottles moved away from Bin A, Bin B, and Bin CSince each of them have only one color left each time, that Bins moved away from can be restated as Bottles that are originally in the Bin but are not of the same color as the one left in Bin That said, if Bin A is to become the bin containing brown bottles, the cost from Bin A will be the summation of other two colors.With some more maths, we can get here:cost = Total number of bottles - ( Bottles that are originally in Bin A, Bin B, and Bin C which has that same color as what the Bin contains now )(All right, my description sucks)What I mean by that is, if there are 10 browns in Bin A, and that bin ended up being the one containing browns, those 10 are counted as what I called bottles that are .....With logic, we know that minimizing cost is the same as maximizing Bottles that are originally in Bin A, Bin B, and Bin C which has that same color as what the Bin contains nowA graphical approach will be to draw a 3 by 3 matrix, and for each column you have to select an element whose row cannot be the one selected by any previous columns. Minimize the summation of selected elements.I've switched how the order of bottles in each bin is saved. From BGC to BCG, so the one with lower dictionary order always comes first if carrying the same cost.Here's my code:#include <iostream>std::string Colors[] = {B, C, G};struct bin{    unsigned int _bottles[3];};int main(int argc, char *argv[]){    bin _bins[3];    unsigned short int _currentConfiguration[3];    unsigned short int _currentMaximum = 0;    unsigned short int _totalBottles = 0;    while ( std::cin >> _bins[0]._bottles[0] )    {        _currentMaximum = 0;        _totalBottles = 0;        for ( unsigned short int i = 0 ; i < 3 ; ++ i )        {            for ( unsigned short int j = 0 ; j < 3 ; ++ j )            {                if ( i == 0 && j == 0 ) continue;                if ( j == 1 ) std::cin >> _bins[i]._bottles[2];                else if ( j == 2 ) std::cin >> _bins[i]._bottles[1];                else std::cin >> _bins[i]._bottles[j];            }        }        for ( unsigned short int i = 0 ; i < 3 ; ++ i )        {            for ( unsigned short int j = 0 ; j < 3 ; ++ j )            {                if ( j == i ) continue;                for ( unsigned short int k = 0 ; k < 3 ; ++ k )                {                    if ( k == i || k == j ) continue;                    unsigned short int _currentCost = _bins[0]._bottles[i] + _bins[1]._bottles[j] + _bins[2]._bottles[k];                    if ( _currentCost > _currentMaximum )                    {                        _currentMaximum = _currentCost;                        _currentConfiguration[0] = i;                        _currentConfiguration[1] = j;                        _currentConfiguration[2] = k;                    }                }            }        }        for ( unsigned short int i = 0 ; i < 3 ; ++ i )        {            for ( unsigned short int j = 0 ; j < 3 ; ++ j )            {                _totalBottles += _bins[i]._bottles[j];            }        }        for ( unsigned short int i = 0 ; i < 3 ; ++ i )        {            std::cout << Colors[_currentConfiguration[i]];        }        std::cout <<  ;        std::cout << _totalBottles - _currentMaximum;        std::cout << std::endl;    }    return 0;}
UVa 102 - Ecology Bin Packing Wrong Answer
c++;contest problem
The answer is very trivial - the int overflow. The condition says:The total number of bottles will never exceed 2^31. It's unsigned int type and you use unsigned short int. Just fix it and you'll get:Hi,This is an automated response from UVa Online Judge.Your submission with number 11805530 for the problem 102 - Ecological Bin Packing has succeeded with verdict Accepted.Congratulations! Now it is time to try a new problem.Best regards,The UVa Online Judge team