Logo
(追記) (追記ここまで)

31152번 - Replace Sort 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB45191854.545%

문제

Consider an array $A$ and a set $B$ of integers such that all numbers in $A$ and $B$ are distinct. Your task is to turn $A$ into a sorted array. To do this you can take any number from $B$ and replace any element of $A$ with it. You can perform this operation any number of times, but each element of $B$ can be used at most once.

Determine the minimum number of operations needed to turn $A$ into a sorted array, or determine that it is impossible.

입력

The first line of input contains two integers $N$ and $M$ (1ドル \le N, M \le 5 \cdot 10^5$) --- the sizes of $A$ and $B$ respectively.

The second line contains $N$ integers $A_1, A_2, \ldots, A_N$.

The third line contains $M$ integers $B_1, B_2, \ldots, B_M$.

All the $(N + M)$ elements are distinct, positive and do not exceed 10ドル^9$.

출력

If it is impossible to turn $A$ into a sorted array, print $-1$. Otherwise, print the minimum number of operations needed.

제한

예제 입력 1

4 1
2 6 13 10
5

예제 출력 1

-1

예제 입력 2

4 2
2 6 13 10
5 4

예제 출력 2

2

예제 입력 3

4 3
2 6 13 10
5 4 19

예제 출력 3

1

노트

In all three examples, the issue is that 13ドル > 10,ドル so we have to change at least one of them.

In the first one, we can decrease 13ドル$ by replacing it with 5ドル,ドル but it breaks the other side, so there is no solution.

In the second one, we also have 4ドル,ドル which we can use to fix the broken side. It is impossible to do with less than 2ドル$ operations.

In the third example we can finally increase the last element, thus fixing $A$ in 1 operation.

출처

Contest > Open Cup > 2021/2022 Season > Stage 7: Grand Prix of Southeastern Europe G번

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2021 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /