CF1211B.Traveling Around the Golden Ring of Berland

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Golden Ring is the special tourist route in Berland. This route consists of nn cities and the cyclic railway route. Cities are numbered from 11 to nn so that:

  • the next city for 11 is the city 22,
  • the next city for 22 is the city 33,
  • ...
  • the next city for nn is the city 11.

Thus, the route is a cycle, cities are numbered in the direction of travel (the route is directed in one way).

Blogger Polycarp wants to start his journey in the city 11. For each city he knows the value aia_i — how many selfies he wants to do in ii-th city. He can take no more than one selfie in one visit to each city. Since he is traveling by train, he can't skip the city (he always moves from the city ii to the city i+1i+1 for 1≤i<n1 \le i \lt n and from nn to 11). Thus, when the train stops in the city, Polycarp must visit this city. If Polycarp visits the city multiple times, all visits are counted separately.

What is the least number of city visits Polycarp will have to complete to fulfill his plan for the number of selfies for each city? Note that he always visits the city 11, since it is this city that his journey begins in.

“黄金环线”是贝尔兰的一条特色旅游线路。该线路由 nn 座城市和一条环形铁路线路组成。城市编号为 11 至 nn,满足如下规则:

  • 城市 11 的下一座城市是城市 22,
  • 城市 22 的下一座城市是城市 33,
  • …
  • 城市 nn 的下一座城市是城市 11。

因此,该线路构成一个环,城市编号顺序与旅行方向一致(即该线路为单向行驶)。

博主 Polycarp 计划从城市 11 出发开始他的旅程。对于每座城市 ii,他已知一个数值 aia_i —— 表示他在第 ii 座城市希望拍摄的自拍照数量。他在每次访问某座城市时最多只能拍一张自拍照。由于他乘坐火车旅行,无法跳过任何城市(即他总是从城市 ii 移动到城市 i+1i+1(其中 1≤i<n1 \le i < n),再从城市 nn 返回城市 11)。因此,每当火车在某座城市停靠时,Polycarp 必须访问该城市。若 Polycarp 多次访问同一座城市,则每次访问均被单独计数。

为完成他在每座城市的自拍计划,Polycarp 至少需要访问多少次城市?注意:他一定访问城市 11,因为他的旅程正是从该城市开始的。

输入格式

The first line contains an integer nn (3≤n≤2⋅1053 \le n \le 2\cdot10^5) — the number of cities in the Golden Ring of Berland.

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤1090 \le a_i \le 10^9), where aia_i is equal to the required number of selfies in the ii-th city.

It is guaranteed that at least one of the numbers aia_i is strictly greater than zero.

第一行包含一个整数 nn(3≤n≤2⋅1053 \le n \le 2\cdot10^5)—— 表示“伯兰金环”中的城市数量。

下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \le a_i \le 10^9),其中 aia_i 表示第 ii 个城市所需的自拍照数量。

保证至少有一个 aia_i 严格大于零。

输出格式

Print a single integer — the required minimum number of visits.

输出一个整数——所需的最少访问次数。

输入输出样例

  • 输入#1

    3
    1 0 0

    输出#1

    1
  • 输入#2

    3
    2 0 2

    输出#2

    6
  • 输入#3

    5
    0 3 1 3 2

    输出#3

    14
  • 输入#4

    5
    1000000000 1000000000 1000000000 1000000000 0

    输出#4

    4999999999

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

首页