Advertisement
Mahmoud_Hawara

Untitled

Mar 7th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. const long long N = 2e5 + 5, MOD = 1e9 + 7, OO = 1e18;
  5. const double PI = acos(-1);
  6. const int dx[4] = {0, 0, 1, -1};
  7. const int dy[4] = {1, -1, 0, 0};
  8.  
  9. long long n, a[3][N], mem[N][3];
  10.  
  11. long long solve(long long idx, long long s) {
  12.     if (idx == n + 1)return 0;
  13.     long long &ret = mem[idx][s];
  14.     if (!ret)return ret;
  15.     long long c1 = -OO, c2 = -OO, c3 = -OO;
  16.     if (s == 0 || s == 2)
  17.         c1 = a[1][idx] + solve(idx + 1, 1LL);
  18.     if (s == 0 || s == 1)
  19.         c2 = a[2][idx] + solve(idx + 1, 2LL);
  20.     c3 = solve(idx + 1, s);
  21.     return ret = max({c1, c2, c3});
  22. }
  23.  
  24. int main() {
  25.     IO
  26.     memset(mem, -1, sizeof mem);
  27.     cin >> n;
  28.     for (int i = 1; i <= 2; i++)
  29.         for (int j = 1; j <= n; j++)cin >> a[i][j];
  30.     cout << solve(1LL, 0LL);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement