Skip to content

Commit

Permalink
Finish LeetCode3259.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiser-Yang committed Aug 30, 2024
1 parent 759aeba commit 1ae8b4f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LeetCode/LeetCode3259.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// problem statement: https://leetcode.cn/problems/maximum-energy-boost-from-two-drinks/description/

#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
long long maxEnergyBoost(vector<int>& energyDrinkA, vector<int>& energyDrinkB) {
int n = energyDrinkA.size();
vector<long long> dp[2] = {vector<long long>(n, 0), vector<long long>(n, 0)};
dp[0][0] = energyDrinkA[0];
dp[1][0] = energyDrinkB[0];
for (int i = 1; i < n; i++) {
dp[0][i] = max(dp[1][i - 1], dp[0][i - 1] + energyDrinkA[i]);
dp[1][i] = max(dp[0][i - 1], dp[1][i - 1] + energyDrinkB[i]);
}
return max(dp[0][n - 1], dp[1][n - 1]);
}
};

0 comments on commit 1ae8b4f

Please sign in to comment.