SRM464 ColorfulBoxesAndBalls

You are playing a game where you have numRed red boxes, numBlue blue boxes, numRed red balls, and numBlue blue balls.

You must place a single ball into each box. Each box is then scored as follows:
If the box is red and it contains a red ball, you get onlyRed points.
If the box is blue and it contains a blue ball, you get onlyBlue points.
In all other cases, you get bothColors points.
Your total score is the sum of the scores of all the boxes.

Return the maximum possible total score you can get.

#include <algorithm>
#include <limits.h>
using namespace std;

class ColorfulBoxesAndBalls {
    public:
        int getMaximum(int numRed, int numBlue, int onlyRed, int onlyBlue, int bothColors){
            int ans = INT_MIN;
            int change = min(numRed, numBlue);

            for(int i =0; i <= change; i++){
                int myscore = (numRed - i) * onlyRed
                    + (numBlue - i) * onlyBlue
                    + 2 * i * bothColors;
                ans = max(ans, myscore);
            }
            return ans;
        }
};

max値をfor文で回して、全パターンの最大値を検索するアルゴリズム
数が少ない方をchangeと定義するのがみそ