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

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter17: Markov Chains
Section: Chapter Questions
Problem 12RP
icon
Related questions
Question

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 ai:=x. This activity should be possible provided that I doesn't have a place with the set b. 

 

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.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Intelligent Machines
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole