CF1437E.Make It Increasing

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array of nn integers a1a_1, a2a_2, ..., ana_n, and a set bb of kk distinct integers from 11 to nn.

In one operation, you may choose two integers ii and xx (1≤i≤n1 \le i \le n, xx can be any integer) and assign ai:=xa_i := x. This operation can be done only if ii does not belong to the set bb.

Calculate the minimum number of operations you should perform so the array aa is increasing (that is, a1<a2<a3<⋯<ana_1 \lt a_2 \lt a_3 \lt \dots \lt a_n), or report that it is impossible.

给你一个包含 nn 个整数的数组 a1a_1, a2a_2, ..., ana_n,以及一个由 kk 个互不相同的整数构成的集合 bb,其中每个元素均在 11 到 nn 之间。

在一次操作中,你可以选择两个整数 ii 和 xx(满足 1≤i≤n1 \le i \le n,xx 可为任意整数),并令 ai:=xa_i := x。但该操作仅在 ii 不属于集合 bb 时才允许执行。

请计算使数组 aa 严格递增(即满足 a1<a2<a3<⋯<ana_1 \lt a_2 \lt a_3 \lt \dots \lt a_n)所需的最少操作次数;若无法实现,则报告不可能。

输入格式

The first line contains two integers nn and kk (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5, 0≤k≤n0 \le k \le n) — the size of the array aa and the set bb, respectively.

The second line contains nn integers a1a_1, a2a_2, ..., ana_n (1≤ai≤1091 \le a_i \le 10^9).

Then, if k≠0k \ne 0, the third line follows, containing kk integers b1b_1, b2b_2, ..., bkb_k (1≤b1<b2<⋯<bk≤n1 \le b_1 \lt b_2 \lt \dots \lt b_k \le n). If k=0k = 0, this line is skipped.

第一行包含两个整数 nn 和 kk(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5,0≤k≤n0 \le k \le n)—— 分别表示数组 aa 的大小和集合 bb 的大小。

第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n(1≤ai≤1091 \le a_i \le 10^9)。

接着,若 k≠0k \ne 0,则第三行给出 kk 个整数 b1b_1, b2b_2, ..., bkb_k(1≤b1<b2<⋯<bk≤n1 \le b_1 \lt b_2 \lt \dots \lt b_k \le n);若 k=0k = 0,则跳过该行。

输出格式

If it is impossible to make the array aa increasing using the given operations, print −1-1.

Otherwise, print one integer — the minimum number of operations you have to perform.

如果无法通过给定的操作使数组 aa 严格递增,则输出 −1-1。

否则,输出一个整数——你需要执行的最少操作次数。

输入输出样例

  • 输入#1

    7 2
    1 2 1 1 3 5 1
    3 5

    输出#1

    4
  • 输入#2

    3 3
    1 3 2
    1 2 3

    输出#2

    -1
  • 输入#3

    5 0
    4 3 1 2 3

    输出#3

    2
  • 输入#4

    10 3
    1 3 5 6 12 9 8 10 13 15
    2 4 9

    输出#4

    3

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

首页