Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- typedef long long LL;
- const int maxn=1e5+2;
- int n;
- int a[maxn],b[maxn];
- LL dp[3][maxn];
- void DP(){
- dp[0][1]=a[1];
- dp[1][1]=b[1];
- for (int i=1;i<=n;i++){
- dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
- dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
- dp[2][i]=max(dp[0][i-1],dp[1][i-1]);
- }
- }
- int main(){
- scanf("%d",&n);
- for (int i=1;i<=n;i++) scanf("%d",&a[i]);
- for (int i=1;i<=n;i++) scanf("%d",&b[i]);
- DP();
- printf("%I64d",max(dp[0][n],max(dp[1][n],dp[2][n])));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement