CF924C.Riverside Curio

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.

Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to m__i.

Define d__i as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of d__i over all days. There are no marks on the channel before the first day.

阿尔卡季决定连续观察一条河流 nn 天。每天河流的水位为某个实数值。

阿尔卡季每天都会前往河边,并在河岸侧壁上标记当天的水位高度;但如果该高度处已有先前做好的标记,则不再新增标记。河水不会冲刷掉已有标记。阿尔卡季每天记录下严格高于当日水位的标记数量;第 ii 天该数值记为 mim_i。

定义 did_i 为第 ii 天严格低于当日水位的标记数量。你需要求出所有天数中 did_i 的总和的最小可能值。在第一天之前,河岸上没有任何标记。

输入格式

The first line contains a single positive integer n (1 ≤ n ≤ 105) — the number of days.

The second line contains n space-separated integers _m_1, _m_2, ..., m__n (0 ≤ m__i < i) — the number of marks strictly above the water on each day.

第一行包含一个正整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 表示天数。

第二行包含 nn 个用空格分隔的整数 m1, m2, ..., mnm_1,\,m_2,\,...,\,m_n(0≤mi<i0 \leq m_i < i)—— 表示每一天严格高于水面的标记数量。

输出格式

Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days.

输出一个整数——所有天中严格低于水位线的标记数量之和的最小可能值。

输入输出样例

  • 输入#1

    6
    0 1 0 3 0 2

    输出#1

    6
  • 输入#2

    5
    0 1 2 1 2

    输出#2

    1
  • 输入#3

    5
    0 1 1 2 2

    输出#3

    0

说明/提示

In the first example, the following figure shows an optimal case.

Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.

In the second example, the following figure shows an optimal case.

在第一个例子中,下图展示了一种最优情况。

注意:在第 3 天必须创建一个新的标记,否则无法在第 4 天保证有 3 个标记位于水面以上。所有标记位于水下的总次数为 0 + 0 + 2 + 0 + 3 + 1 = 60 + 0 + 2 + 0 + 3 + 1 = 6。

在第二个例子中,下图展示了一种最优情况。

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

首页