Herb Mixing
InterviewTime limit1sMemory limit2048 MB
Given counts of green and red herbs, find the maximum health boost from combining them using the listed recipes.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
Leon has collected some herbs of two possible colors: green and red. Leon's health level will be boosted after he eats those herbs. Mixing the herbs can increase their effect according to the following recipes:
- One green herb: Boosts health by .
- Two green herbs: Boosts health by .
- Three green herbs: Boosts health by .
- One green herb and one red herb: Boosts health by .
The herbs cannot be consumed in any way other than those listed above.
What is the maximum amount of Leon's health that can be boosted if he optimally mixes and eats his herbs?
Input
Input contains two integers between and (both inclusive), the number of green herbs and the number of red herbs that Leon has collected.
Output
Output a single integer, the maximum amount of Leon's health that can be boosted.