You are given a variety of n integers a1, a2, ..., an, and a set b of k unmistakable integers from 1 to n. In one activity, you might pick two integers I and x (1≤i≤n, x can be any integer) and allocate ai:=x. This activity should be possible provided that I doesn't have a place with the set b. Compute the base
Correct answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science.
You are given a variety of n integers a1, a2, ..., an, and a set b of k unmistakable integers from 1 to n.
In one activity, you might pick two integers I and x (1≤i≤n, x can be any integer) and allocate
Compute the base number of tasks you ought to perform so the cluster an is expanding (that is, a1<a2<a3<⋯<an), or report that it is inconceivable.
Input
The principal line contains two integers n and k (1≤n≤5⋅105, 0≤k≤n) — the size of the exhibit an and the set b, individually.
The subsequent line contains n integers a1, a2, ..., an (1≤ai≤109).
Then, at that point, if k≠0, the third line follows, containing k integers b1, b2, ..., bk (1≤b1<b2<⋯<bk≤n). On the off chance that k=0, this line is skipped.
Output
In case it is difficult to make the exhibit an expanding utilizing the given tasks, print −1.
In any case, print one integer — the base number of tasks you need to perform.
Step by step
Solved in 4 steps with 1 images