A13664 | Omkar and Circle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$ ). Formally, for all $i$ such that $2 \leq i \leq n$ , the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$ ). Formally, for all $i$ such that $2 \leq i \leq n$ , the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
输入格式
The first line contains one odd integer $n$ ( $1 \leq n < 2 \cdot 10^5$ , $n$ is odd) — the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ( $0 \leq a_{i} \leq 10^9$ ) — the initial numbers in the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ( $0 \leq a_{i} \leq 10^9$ ) — the initial numbers in the circle.
输出格式
Output the maximum possible circular value after applying some sequence of operations to the given circle.
输入输出样例
输入 #1
3 7 10 2
输出 #1
17
输入 #2
1 4
输出 #2
4
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$ . The sum of adjacent elements equals $17$ . Delete $7$ and $10$ from the circle and replace $2$ with $17$ .
Note that the answer may not fit in a $32$ -bit integer.
Pick the number at index $3$ . The sum of adjacent elements equals $17$ . Delete $7$ and $10$ from the circle and replace $2$ with $17$ .
Note that the answer may not fit in a $32$ -bit integer.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted