CBOJ 2022 Spring Contest Problem 3 - Martin's Monochromatic Marbles
Martin is a colored marble enthusiast.
He has \(3N\) unicolored marbles (\(R\) red ones, \(G\) green ones, and \(B\) blue ones), that he wants to partition into \(N\) groups of \(3\) marbles each. Because Martin is a chaotic individual, he calls groups with all marbles having the same color bad. Assuming he divides the marbles optimally, what is the minimum number of bad groups that Martin can form?
Input Specification
The first line will contain the integer \(N\) \((1\le N\le 10^{18})\), the number of groups Martin wishes to form.
The second line will have three space-separated integers \(R\), \(G\), and \(B\) \((0\le R,G,B \le 3N)\), representing the number of marbles of each color that Martin has. Note that \(R+G+B=3N\).
Output Specification
An integer representing the minimum number of bad groups.
Subtasks
Subtask 1 [40%]
\(B=0\)
Subtask 2 [60%]
No additional constraints.
Sample Input 1
1
1 2 0
Sample Output 1
0
Sample Input 2
58
147 5 22
Sample Output 2
31
Comments