Choose at most one drink per hour from two energy-drink sequences, without taking from the same drink in consecutive hours, to maximize total energy boost.
Problem
You are given two arrays of integers, drink1 and drink2, each representing the energy boost you gain from drinking one bottle at each hour.
You may choose at most one drink in each hour, and if you drink at hour i, then on hour i + 1 you may not choose the same drink again.
Your task is to compute the maximum total energy boost you can obtain.
In other words:
- At each hour, you may skip drinking.
- If you choose from
drink1at houri, then at houri+1you cannot choosedrink1again. - If you choose from
drink2at houri, then at houri+1you cannot choosedrink2again. - You want the largest possible sum of boosts over all hours.
Notes
- The two arrays have the same length.
- You may choose no drink at some hours.
- The goal is to maximize the total sum, not the number of drinks chosen.
Input Format
- Two integer arrays
drink1anddrink2 drink1.length == drink2.length == ndrink1[i]anddrink2[i]are the boosts available at hourifrom each drink
Output Format
- Return a single integer: the maximum total energy boost achievable under the constraints.
Constraints
1 <= n <= $10^{5}$$-10^{9}$ <= drink1[i], drink2[i] <= $10^{9}$- Choose at most one drink per hour
- The same drink cannot be chosen in two consecutive hours
Example 1
Input
drink1 = [4, 2, 7] drink2 = [1, 5, 3]
Output
12
Explanation
One optimal plan is:
- Hour 0: take drink1 = 4
- Hour 1: take drink2 = 5
- Hour 2: take drink1 = 7
Total = 4 + 5 + 7 = 16.
If the intended interpretation is that you can take only one drink total per hour and cannot take both, this sequence is valid because the chosen drink alternates each hour.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.