CF946G.Almost Increasing Array

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it).

You are given an array a consisting of n elements. You are allowed to replace any element with any integer number (and you may do so any number of times you need). What is the minimum number of replacements you have to perform in order to make the array almost increasing?

我们称一个数组是“几乎递增”的,如果至多删除其中的一个元素后,该数组能变成严格递增的(即每个元素都严格大于其前面的所有元素)。

给你一个由 nn 个元素组成的数组 aa。你被允许将任意元素替换为任意整数(且可执行任意多次这样的操作)。为了使该数组变为“几乎递增”的,你最少需要执行多少次替换操作?

输入格式

The first line contains one integer n (2 ≤ n ≤ 200000) — the number of elements in a.

The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109) — the array a.

第一行包含一个整数 nn(2≤n≤2000002 \leq n \leq 200000)—— 表示数组 aa 中的元素个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 表示数组 aa。

输出格式

Print the minimum number of replaces you have to perform so that a is almost increasing.

输出使序列 aa 成为“近似递增”序列所需的最少替换次数。

输入输出样例

  • 输入#1

    5
    5 4 3 2 1

    输出#1

    3
  • 输入#2

    5
    1 2 8 9 5

    输出#2

    0

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

首页