#include <iostream>
using namespace std;
class ColorfulBoxesAndBalls{
public:
int getMaximum(int numRed,int numBlue,int onlyRed,int onlyBlue,int bothColors);
};
int ColorfulBoxesAndBalls::getMaximum(int numRed,int numBlue,int onlyRed,int onlyBlue,int bothColors){
int bigger,smaller,big_score,small_score,max_score=0;
int min=0;
if(onlyRed<onlyBlue){
min=onlyRed;
}else{
min=onlyBlue;
};
if(bothColors<min){
min=bothColors;
};
max_score=(numBlue+numRed)*min;
if(numRed>numBlue){
bigger=numRed;
smaller=numBlue;
big_score=onlyRed;
small_score=onlyBlue;
}else{
bigger=numBlue;
smaller=numRed;
big_score=onlyBlue;
small_score=onlyRed;
}
//check i [small] ball in j [big] box
for(int i=0;i<=smaller;i++){
int big_in_big=bigger-i;
int small_in_small=smaller-i;
int cross=i*2;
int score=big_score*big_in_big+small_score*small_in_small+bothColors*cross;
if(max_score<score){
max_score=score;
}
}
return max_score;
}
int main(){
ColorfulBoxesAndBalls cbb;
int result=cbb.getMaximum(2,3,100,400,200);
cout<<"result:"<<result<<endl;
return 0;
}
04-08