C. Basketball Exercise

194 篇文章 1 订阅
32 篇文章 0 订阅

链接:https://codeforces.com/contest/1195/problem/C

Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2⋅n2⋅n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly nn people in each row). Students are numbered from 11 to nn in each row in order from left to right.

bf391a96cdb51467057f2a6fae4d88e745e0fc53.pnguploading.4e448015.gif转存失败重新上传取消

Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n2n students (there are no additional constraints), and a team can consist of any number of students.

Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.

Input

The first line of the input contains a single integer nn (1≤n≤1051≤n≤105) — the number of students in each row.

The second line of the input contains nn integers h1,1,h1,2,…,h1,nh1,1,h1,2,…,h1,n (1≤h1,i≤1091≤h1,i≤109), where h1,ih1,i is the height of the ii-th student in the first row.

The third line of the input contains nn integers h2,1,h2,2,…,h2,nh2,1,h2,2,…,h2,n (1≤h2,i≤1091≤h2,i≤109), where h2,ih2,i is the height of the ii-th student in the second row.

Output

Print a single integer — the maximum possible total height of players in a team Demid can choose.

Examples

input

Copy

5
9 3 5 7 3
5 8 1 4 5

output

Copy

29

input

Copy

3
1 2 9
10 1 1

output

Copy

19

input

Copy

1
7
4

output

Copy

7

Note

In the first example Demid can choose the following team as follows:

 

In the second example Demid can choose the following team as follows:

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,t,d,s,k;
long long a[10000001],b[1000001];
long long dp[1000001][3];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	dp[1][0]=0;
	dp[1][1]=a[1];
	dp[1][2]=b[1];
	for(int i=2;i<=n;i++)
	{
		dp[i][0]=max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2]));
		dp[i][1]=max(dp[i-1][0]+a[i],dp[i-1][2]+a[i]);
		dp[i][2]=max(dp[i-1][0]+b[i],dp[i-1][1]+b[i]);
	}
	cout<<max(dp[n][1],max(dp[n][0],dp[n][2]));
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值