Created
August 29, 2019 17:46
-
-
Save Rockbet/79a3afcc1b7a822171979f3d765ebadc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
const int maxn = 1e5+100; | |
int n, h[3][maxn]; | |
long long dp[3][maxn]; | |
long long solve(int fila, int col){ | |
if(col>=n)return dp[fila][col] = h[fila][col]; | |
if(dp[fila][col]!=-1) return dp[fila][col]; | |
long long caso1, caso2; | |
if(fila==1){ | |
caso1 = solve(2, col+1); | |
caso2 = solve(2, col+2); | |
} | |
if(fila==2){ | |
caso1 = solve(1, col+1); | |
caso2 = solve(1, col+2); | |
} | |
return dp[fila][col] = h[fila][col] + max(caso1, caso2); | |
} | |
main(){ | |
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); | |
cin >> n; | |
for(int i=1; i<=2; i++){ | |
for(int j=1; j<=n; j++){ | |
cin >> h[i][j]; | |
} | |
} | |
memset(dp, -1, sizeof dp); | |
solve(1, 1); | |
solve(2, 1); | |
long long resp = max(dp[1][1], dp[2][1]); | |
cout << resp << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment