CF1437E.Make It Increasing
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of n integers a1, a2, ..., an, and a set b of k distinct integers from 1 to n.
In one operation, you may choose two integers i and x (1≤i≤n, x can be any integer) and assign ai:=x. This operation can be done only if i does not belong to the set b.
Calculate the minimum number of operations you should perform so the array a is increasing (that is, a1<a2<a3<⋯<an), or report that it is impossible.
给你一个包含 n 个整数的数组 a1, a2, ..., an,以及一个由 k 个互不相同的整数构成的集合 b,其中每个元素均在 1 到 n 之间。
在一次操作中,你可以选择两个整数 i 和 x(满足 1≤i≤n,x 可为任意整数),并令 ai:=x。但该操作仅在 i 不属于集合 b 时才允许执行。
请计算使数组 a 严格递增(即满足 a1<a2<a3<⋯<an)所需的最少操作次数;若无法实现,则报告不可能。
输入格式
The first line contains two integers n and k (1≤n≤5⋅105, 0≤k≤n) — the size of the array a and the set b, respectively.
The second line contains n integers a1, a2, ..., an (1≤ai≤109).
Then, if k=0, the third line follows, containing k integers b1, b2, ..., bk (1≤b1<b2<⋯<bk≤n). If k=0, this line is skipped.
第一行包含两个整数 n 和 k(1≤n≤5⋅105,0≤k≤n)—— 分别表示数组 a 的大小和集合 b 的大小。
第二行包含 n 个整数 a1, a2, ..., an(1≤ai≤109)。
接着,若 k=0,则第三行给出 k 个整数 b1, b2, ..., bk(1≤b1<b2<⋯<bk≤n);若 k=0,则跳过该行。
输出格式
If it is impossible to make the array a increasing using the given operations, print −1.
Otherwise, print one integer — the minimum number of operations you have to perform.
如果无法通过给定的操作使数组 a 严格递增,则输出 −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测评打分。不知道怎么写?