CF1437E.Make It Increasing

普及/提高-

通过率:0%

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 ( 1in1 \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 < a_2 < a_3 < \dots < a_n ), or report that it is impossible.

输入格式

The first line contains two integers nn and kk ( 1n51051 \le n \le 5 \cdot 10^5 , 0kn0 \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 ( 1ai1091 \le a_i \le 10^9 ).

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

输出格式

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.

输入输出样例

  • 输入#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
首页