<p>You are given two integer arrays <code>energyDrinkA</code> and <code>energyDrinkB</code> of the same length <code>n</code> by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.</p>

<p>You want to <em>maximize</em> your total energy boost by drinking one energy drink <em>per hour</em>. However, if you want to switch from consuming one energy drink to the other, you need to wait for <em>one hour</em> to cleanse your system (meaning you won&#39;t get any energy boost in that hour).</p>

<p>Return the <strong>maximum</strong> total energy boost you can gain in the next <code>n</code> hours.</p>

<p><strong>Note</strong> that you can start consuming <em>either</em> of the two energy drinks.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> energyDrinkA<span class="example-io"> = [1,3,1], </span>energyDrinkB<span class="example-io"> = [3,1,1]</span></p>

<p><strong>Output:</strong> <span class="example-io">5</span></p>

<p><strong>Explanation:</strong></p>

<p>To gain an energy boost of 5, drink only the energy drink A (or only B).</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> energyDrinkA<span class="example-io"> = [4,1,1], </span>energyDrinkB<span class="example-io"> = [1,1,3]</span></p>

<p><strong>Output:</strong> <span class="example-io">7</span></p>

<p><strong>Explanation:</strong></p>

<p>To gain an energy boost of 7:</p>

<ul>
	<li>Drink the energy drink A for the first hour.</li>
	<li>Switch to the energy drink B and we lose the energy boost of the second hour.</li>
	<li>Gain the energy boost of the drink B in the third hour.</li>
</ul>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == energyDrinkA.length == energyDrinkB.length</code></li>
	<li><code>3 &lt;= n &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= energyDrinkA[i], energyDrinkB[i] &lt;= 10<sup>5</sup></code></li>
</ul>

'''
    Find the max of total energy boost

    A: [5,3,1]
    B: [3,1,100]

    Greedy/DP Problem
    B, wait 1 hr, A (3->1) = 4

    A, wait 1 hr, B

    Let DP(2,i) be the max total energy boost at any point of i

    With 1 element,
    max(A,B) => 5,3 = 5


    With 2 elements
    DP    0  1  2  3
    0     0  5 max(DP(0,1)+arr(0,2), max(DP(1,0)+arr(0,2))
    1     0  3 

    arr   0  1  2
    0     4  1  1           i
    1     1  1  3           j

    DP  0 1 2 3
    0   0 1 4 5
    1   0 3
    dp(0,3) = dp(0,2) + arr(0,2) OR dp(1,1) + arr(0,2)
'''

class Solution:
    def maxEnergyBoost(self, energyDrinkA: List[int], energyDrinkB: List[int]) -> int:
        n = len(energyDrinkA)
        dp = [[0 for _ in range(n+1)] for _ in range(2)] # Row 0, Row 1

        for j in range(0,n):
            for i in range(2):
                if j + 1 <= n:
                    if i == 0:
                        dp[i][j+1] = max(dp[i][j]+energyDrinkA[j], dp[i][j+1])
                    else:        
                        dp[i][j+1] = max(dp[i][j]+energyDrinkB[j], dp[i][j+1])
                if j + 2 <= n:
                    if i == 0:
                        dp[i][j+2] = max(dp[i+1][j]+energyDrinkA[j+1], dp[i][j+2])
                    else:
                        dp[i][j+2] = max(dp[i-1][j]+energyDrinkB[j+1], dp[i][j+2])
        res = 0
        for i in dp:
            res = max(res, i[n])
        return res      
1983