CF1372D.Omkar and Circle

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!

You are given nn nonnegative integers a1,a2,…,ana_1, a_2, \dots, a_n arranged in a circle, where nn must be odd (ie. n−1n-1 is divisible by 22). Formally, for all ii such that 2≤i≤n2 \leq i \leq n, the elements ai−1a_{i - 1} and aia_i are considered to be adjacent, and ana_n and a1a_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.

丹尼,当地的数学狂人,对奥姆卡尔最新创作的圆非常着迷。请帮助他解决这个关于圆的问题!

给你 nn 个非负整数 a1,a2,…,ana_1, a_2, \dots, a_n,它们按顺时针(或逆时针)顺序排列在一个圆上,其中 nn 必须为奇数(即 n−1n-1 能被 22 整除)。形式化地说,对所有满足 2≤i≤n2 \leq i \leq n 的 ii,元素 ai−1a_{i - 1} 和 aia_i 被视为相邻;此外,ana_n 和 a1a_1 也被视为相邻。在一次操作中,你从圆上选择一个数,将其替换为它的两个相邻元素之和,然后将这两个相邻元素从圆中删除。重复该操作,直到圆中仅剩一个数,我们称其为圆值(circular value)。

请帮助丹尼找出经过若干次操作后所能得到的最大可能的圆值。

输入格式

The first line contains one odd integer nn (1≤n<2⋅1051 \leq n \lt 2 \cdot 10^5, nn is odd) — the initial size of the circle.

The second line contains nn integers a1,a2,…,ana_{1},a_{2},\dots,a_{n} (0≤ai≤1090 \leq a_{i} \leq 10^9) — the initial numbers in the circle.

第一行包含一个奇数 nn(1≤n<2⋅1051 \leq n \lt 2 \cdot 10^5,且 nn 为奇数)—— 圆圈的初始大小。

第二行包含 nn 个整数 a1,a2,…,ana_{1},a_{2},\dots,a_{n}(0≤ai≤1090 \leq a_{i} \leq 10^9)—— 圆圈中的初始数字。

输出格式

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 1717 is obtained:

Pick the number at index 33. The sum of adjacent elements equals 1717. Delete 77 and 1010 from the circle and replace 22 with 1717.

Note that the answer may not fit in a 3232-bit integer.

对于第一个测试用例,以下是得到环形值 1717 的过程:

选择索引为 33 处的数字。相邻元素之和等于 1717。从圆圈中删除 77 和 1010,并将 22 替换为 1717。

注意:答案可能超出 3232 位整数的表示范围。

输入解题思路,AI测评打分。不知道怎么写?

首页