How We Coding

### SRM 464 Div2 Level 1 ###



<소스코드>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <algorithm>
using namespace std;
 
class ColorfulBoxesAndBalls {
public:
    int getMaximum(int numRed, int numBlue, int onlyRed, int onlyBlue, int bothColors) {
        int ans=0;
        int minCnt = min(numRed, numBlue);
 
        ans = max(onlyRed+onlyBlue, bothColors*2* minCnt;
        ans += ((numRed-minCnt) * onlyRed);
        ans += ((numBlue-minCnt) * onlyBlue);
        return ans;
    }
};
 
cs


>> 둘중 적은 것의 갯수만큼 섞을 수 있다. 그래서 그 최소개를 제대로 넣은 경우와 섞은 경우중 최대값이 정답이 된다.

>> 나머지에서는 자기 박스에 자기 공을 넣을 것이기 때문에 그 값을 더해주면 된다.