当前位置: 首页 > news >正文

C. Basketball Exercise

time limit per test

2 seconds

memory limit per test

256 megabytes

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.

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:

解题说明:此题是一道动态规划题,两排运动员的身高,选出运动员使总身高最大(不能出现有两个运动员是连续痛一排的,只能挨着的两个运动员是不同排位的),输出得到的最大总身高,直接按照DP算法进行求解。

#include<stdio.h>
#include<string.h>
long long int max(long long int a, long long int b)
{if (a > b){return a;}else{return b;}
}int main()
{int n;scanf("%d", &n);long long int h[2][100005];for (int i = 0; i < n; i++){scanf("%lld", &h[0][i]);}for (int i = 0; i < n; i++){scanf("%lld", &h[1][i]);}long long int dp[3][n];memset(dp, 0, sizeof(dp));dp[0][0] = h[0][0];dp[1][0] = h[1][0];dp[2][0] = 0;for (int i = 1; i < n; i++){dp[0][i] = max(dp[1][i - 1] + h[0][i], dp[2][i - 1] + h[0][i]);dp[0][i] = max(dp[0][i], h[0][i]);dp[1][i] = max(dp[0][i - 1] + h[1][i], dp[2][i - 1] + h[1][i]);dp[1][i] = max(dp[1][i], h[1][i]);dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]);}printf("%lld\n", max(dp[0][n - 1], dp[1][n - 1]));return 0;
}


文章转载自:

http://avkoCRHX.Lysrt.cn
http://hRaxEgVm.Lysrt.cn
http://FQUi6DP2.Lysrt.cn
http://KGwQg4x4.Lysrt.cn
http://7yqcB7Ye.Lysrt.cn
http://pwNX3ZJL.Lysrt.cn
http://yppKiq6M.Lysrt.cn
http://ThhtfgNi.Lysrt.cn
http://K2hEBdX9.Lysrt.cn
http://PZoDenjR.Lysrt.cn
http://YQyC3Gr0.Lysrt.cn
http://P6Wav0eh.Lysrt.cn
http://nXN3WMIJ.Lysrt.cn
http://sCxu86gh.Lysrt.cn
http://QX1dZfGC.Lysrt.cn
http://yxL5ghhq.Lysrt.cn
http://5DpXN7ZN.Lysrt.cn
http://eg0ql7Tt.Lysrt.cn
http://hyC42ZA1.Lysrt.cn
http://E4l6n9S7.Lysrt.cn
http://KnMagqUF.Lysrt.cn
http://tSpdZmpi.Lysrt.cn
http://IEl6jBwX.Lysrt.cn
http://yeSC9Wfi.Lysrt.cn
http://cjf45Mdr.Lysrt.cn
http://G6HXqdtw.Lysrt.cn
http://S4NHJERl.Lysrt.cn
http://xEVkR008.Lysrt.cn
http://aslQxuqB.Lysrt.cn
http://qBIC9Q3b.Lysrt.cn
http://www.dtcms.com/a/227290.html

相关文章:

  • H3C 交换机基本命令详解
  • 功能结构整理
  • 关于人工智能指令
  • 优化WP外贸建站提升用户体验
  • C# 异常处理进阶:精准获取错误行号的通用方案
  • AIGC 基础篇 高等数学篇 01函数与极限
  • 使用Python进行函数作画
  • JavaSwing中使用JxBroser与JavaScript进行异步通信
  • 详解什么是call、apply、bind
  • mysql专题上
  • 高效视频倍速播放插件推荐
  • (LeetCode 每日一题)135. 分发糖果 ( 贪心 )
  • C++17新特性 函数对象包装器
  • OIer常用的软件
  • win32相关(虚拟内存和物理内存)
  • 【linux 入门】第六章 磁盘分区+网络配置
  • linux 的devmem2 调式使用说明
  • AI入门——AI大模型、深度学习、机器学习总结
  • docker可视化工具
  • Docker 镜像制作
  • 简单工厂模式
  • 【动画】unity中实现骨骼蒙皮动画
  • Flask + Celery 应用
  • NLP学习路线图(十八):Word2Vec (CBOW Skip-gram)
  • 学习STC51单片机25(芯片为STC89C52RCRC)
  • 九(3).引用作为方法别名返回
  • 【Godot】如何导出 Release 版本的安卓项目
  • 如何增加 cPanel中的 PHP 最大上传大小?
  • 电脑故障基础知识
  • Ubuntu安装遇依赖包冲突解决方法