CF1437E.Make It Increasing
普及/提高-
通过率:0%
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.
输入格式
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.
输出格式
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.
输入输出样例
输入#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