Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long N = 2e5 + 5, MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- long long n, a[3][N], mem[N][3];
- long long solve(long long idx, long long s) {
- if (idx == n + 1)return 0;
- long long &ret = mem[idx][s];
- if (!ret)return ret;
- long long c1 = -OO, c2 = -OO, c3 = -OO;
- if (s == 0 || s == 2)
- c1 = a[1][idx] + solve(idx + 1, 1LL);
- if (s == 0 || s == 1)
- c2 = a[2][idx] + solve(idx + 1, 2LL);
- c3 = solve(idx + 1, s);
- return ret = max({c1, c2, c3});
- }
- int main() {
- IO
- memset(mem, -1, sizeof mem);
- cin >> n;
- for (int i = 1; i <= 2; i++)
- for (int j = 1; j <= n; j++)cin >> a[i][j];
- cout << solve(1LL, 0LL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement