Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int solution(vector<int> &A, vector<int> &B, int X, int Y) {
- constexpr int NMAX = 1e5 + 3;
- const int n = A.size();
- static int dp[NMAX][2][2];
- dp[0][0][0] = dp[0][0][1] = A[0];
- dp[0][1][0] = dp[0][1][1] = B[0];
- for (int i = 1; i < n; i++) {
- dp[i][0][0] = min(dp[i - 1][0][0], dp[i - 1][0][1]) + A[i];
- dp[i][1][1] = min(dp[i - 1][1][0], dp[i - 1][1][1]) + B[i];
- dp[i][1][0] = min(dp[i - 1][0][0], dp[i - 1][0][1]) + B[i] + X;
- dp[i][0][1] = min(dp[i - 1][1][0], dp[i - 1][1][1]) + A[i] + Y;
- }
- int ans = INT_MAX;
- for (int i = 0; i <= 1; i++) {
- for (int j = 0; j <= 1; j++) {
- ans = min(ans, dp[n - 1][i][j]);
- }
- }
- //cerr << dp[n - 1][0][0] << endl;//*/
- return ans;
- }
- int main() {
- vector<int> a = {2,11,4,4}, b={9,2,5,11};
- cerr << solution(a, b, 8, 4) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement