Advertisement
dudu2004

1195C Basketball Exercise

Jul 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. typedef long long LL;
  5. const int maxn=1e5+2;
  6. int n;
  7. int a[maxn],b[maxn];
  8. LL dp[3][maxn];
  9. void DP(){
  10.     dp[0][1]=a[1];
  11.     dp[1][1]=b[1];
  12.     for (int i=1;i<=n;i++){
  13.         dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
  14.         dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
  15.         dp[2][i]=max(dp[0][i-1],dp[1][i-1]);
  16.     }
  17. }
  18. int main(){
  19.     scanf("%d",&n);
  20.     for (int i=1;i<=n;i++) scanf("%d",&a[i]);
  21.     for (int i=1;i<=n;i++) scanf("%d",&b[i]);
  22.     DP();
  23.     printf("%I64d",max(dp[0][n],max(dp[1][n],dp[2][n])));
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement