A12676 | Basketball Exercise
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ 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) 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 $2n$ 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.
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) 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 $2n$ 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.
输入格式
The first line of the input contains a single integer $n$ ( $1 \le n \le 10^5$ ) — the number of students in each row.
The second line of the input contains $n$ integers $h_{1, 1}, h_{1, 2}, \ldots, h_{1, n}$ ( $1 \le h_{1, i} \le 10^9$ ), where $h_{1, i}$ is the height of the $i$ -th student in the first row.
The third line of the input contains $n$ integers $h_{2, 1}, h_{2, 2}, \ldots, h_{2, n}$ ( $1 \le h_{2, i} \le 10^9$ ), where $h_{2, i}$ is the height of the $i$ -th student in the second row.
The second line of the input contains $n$ integers $h_{1, 1}, h_{1, 2}, \ldots, h_{1, n}$ ( $1 \le h_{1, i} \le 10^9$ ), where $h_{1, i}$ is the height of the $i$ -th student in the first row.
The third line of the input contains $n$ integers $h_{2, 1}, h_{2, 2}, \ldots, h_{2, n}$ ( $1 \le h_{2, i} \le 10^9$ ), where $h_{2, i}$ is the height of the $i$ -th student in the second row.
输出格式
Print a single integer — the maximum possible total height of players in a team Demid can choose.
输入输出样例
输入 #1
5 9 3 5 7 3 5 8 1 4 5
输出 #1
29
输入 #2
3 1 2 9 10 1 1
输出 #2
19
输入 #3
1 7 4
输出 #3
7
In the first example Demid can choose the following team as follows:
In the second example Demid can choose the following team as follows:

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

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted