CF201C.Fragile Bridges
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave this level until you've gained the maximum possible number of points there.
The bonus level consists of n small platforms placed in a line and numbered from 1 to n from left to right and (n - 1) bridges connecting adjacent platforms. The bridges between the platforms are very fragile, and for each bridge the number of times one can pass this bridge from one of its ends to the other before it collapses forever is known in advance.
The player's actions are as follows. First, he selects one of the platforms to be the starting position for his hero. After that the player can freely move the hero across the platforms moving by the undestroyed bridges. As soon as the hero finds himself on a platform with no undestroyed bridge attached to it, the level is automatically ended. The number of points scored by the player at the end of the level is calculated as the number of transitions made by the hero between the platforms. Note that if the hero started moving by a certain bridge, he has to continue moving in the same direction until he is on a platform.
Find how many points you need to score to be sure that nobody will beat your record, and move to the next level with a quiet heart.
你正在玩一款视频游戏,刚刚抵达奖励关卡。该关卡的唯一目标是尽可能多地获得分数。作为一个完美主义者,你已决定:除非在此关卡中获得理论上的最高分,否则绝不离开。
奖励关卡由排成一条直线的 $ n $ 个小型平台组成,平台从左至右依次编号为 $ 1 $ 到 $ n $;此外还有 $ (n-1) $ 座桥连接相邻平台。这些桥极为脆弱,且每座桥在从一端走向另一端时所能承受的通行次数(即单向通行次数)是预先已知的,超过该次数后桥将永久坍塌。
玩家的操作规则如下:首先,选择其中一个平台作为英雄的起始位置;之后,玩家可自由驱使英雄在平台间移动,但仅能通过尚未坍塌的桥通行。一旦英雄所处平台不再连有未坍塌的桥,关卡即自动结束。关卡结束时玩家所得分数,定义为英雄在平台之间完成的移动次数(即跨桥次数)。注意:若英雄通过某座桥开始移动,则必须沿同一方向持续前进,直至抵达某一平台为止。
请计算你必须获得的分数,以确保无人能打破你的纪录,从而安心进入下一关。
输入格式
The first line contains a single integer n (2 ≤ n ≤ 105) — the number of platforms on the bonus level. The second line contains (n - 1) integers a__i (1 ≤ a__i ≤ 109, 1 ≤ i < n) — the number of transitions from one end to the other that the bridge between platforms i and i + 1 can bear.
第一行包含一个整数 n(2≤n≤105)—— 表示奖励关卡中平台的数量。
第二行包含 n−1 个整数 ai(1≤ai≤109,1≤i<n)—— 表示连接第 i 个平台与第 i+1 个平台的桥所能承受的从一端到另一端的通行次数。
输出格式
Print a single integer — the maximum number of points a player can get on the bonus level.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输出一个整数——玩家在奖励关卡中能获得的最高分数。
请注意,在 C++ 中读取或写入 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。
输入输出样例
输入#1
5 2 1 2 1
输出#1
5
说明/提示
One possibility of getting 5 points in the sample is starting from platform 3 and consequently moving to platforms 4, 3, 2, 1 and 2. After that the only undestroyed bridge is the bridge between platforms 4 and 5, but this bridge is too far from platform 2 where the hero is located now.
样例中获得 5 分的一种可能方案是:从平台 3 出发,随后依次移动到平台 4、3、2、1 和 2。此后,唯一尚未被摧毁的桥是连接平台 4 与平台 5 的桥,但此时英雄位于平台 2,该桥距离过远,无法到达。
输入解题思路,AI测评打分。不知道怎么写?