MarbleDecoration
SRM 512 · 2011-05-25 · by fushar
SRM 512 · 2011-05-25 · by fushar · Brute Force, Simple Math, Simple Search, Iteration
Problem Statement
Problem Statement
Ash is a marble collector and he likes to create various ornaments using his marbles.
One day, Elsh asks him to create a simple decoration for her desk. She wants a sequence of marbles consisting of at most two different colors. To make the sequence look interesting, each pair of adjacent marbles must have different colors.
Currently, Ash has R red marbles, G green marbles, and B blue marbles. Elsh wants that the resulting sequence is as long as possible. Return this maximum length.
One day, Elsh asks him to create a simple decoration for her desk. She wants a sequence of marbles consisting of at most two different colors. To make the sequence look interesting, each pair of adjacent marbles must have different colors.
Currently, Ash has R red marbles, G green marbles, and B blue marbles. Elsh wants that the resulting sequence is as long as possible. Return this maximum length.
Constraints
- R will be between 0 and 50, inclusive.
- G will be between 0 and 50, inclusive.
- B will be between 0 and 50, inclusive.
Examples
0)
0 0 0 Returns: 0
Ash currently doesn't have any marbles at all.
1)
3 0 0 Returns: 1
The only valid sequence is (red).
2)
5 1 2 Returns: 5
One possible sequence is (red, blue, red, blue, red).
3)
7 7 4 Returns: 14
4)
0 0 1 Returns: 1
Submissions are judged against all 81 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class MarbleDecoration with a public method int maxLength(int R, int G, int B) · 81 test cases · 2 s / 256 MB per case