Advertisement
STANAANDREY

itec2023 3

Mar 18th, 2023
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int solution(vector<int> &A, vector<int> &B, int X, int Y) {
  5.     constexpr int NMAX = 1e5 + 3;
  6.     const int n = A.size();
  7.     static int dp[NMAX][2][2];
  8.     dp[0][0][0] = dp[0][0][1] = A[0];
  9.     dp[0][1][0] = dp[0][1][1] = B[0];
  10.     for (int i = 1; i < n; i++) {
  11.         dp[i][0][0] = min(dp[i - 1][0][0], dp[i - 1][0][1]) + A[i];
  12.         dp[i][1][1] = min(dp[i - 1][1][0], dp[i - 1][1][1]) + B[i];
  13.         dp[i][1][0] = min(dp[i - 1][0][0], dp[i - 1][0][1]) + B[i] + X;
  14.         dp[i][0][1] = min(dp[i - 1][1][0], dp[i - 1][1][1]) + A[i] + Y;
  15.  
  16.     }
  17.     int ans = INT_MAX;
  18.     for (int i = 0; i <= 1; i++) {
  19.         for (int j = 0; j <= 1; j++) {
  20.             ans = min(ans, dp[n - 1][i][j]);
  21.         }
  22.     }
  23.     //cerr << dp[n - 1][0][0] << endl;//*/
  24.     return ans;
  25. }
  26.  
  27.  
  28. int main() {
  29.     vector<int> a = {2,11,4,4}, b={9,2,5,11};
  30.     cerr << solution(a, b, 8, 4) << endl;
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement