logo AlgoBeat OnlineJudge
登录 注册

#214770. [ICPC 2025 Seoul R] CPEquivalence

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Given an integer array consisting of integers (namely, each item of is an integer), the Closest Position array (CP-array) is an array of length defined to be

where denotes the -th integer in , and the length is the number of integers in . In other words, is the greatest index of that is smaller than and whose item at that index is greater than or equal to . For example, when , its CP-array is , and .

We say that two integer arrays and are CP-equivalent if . It is obvious that two CP-equivalent integer arrays and have the same length. For example, two arrays and are CP-equivalent because their CP-arrays are the same as .

For an integer array , an integer and a non-negative integer , a substitution operation on at position into returns the array . For an integer array and a non-negative integer , a deletion operation on at position returns the array . Finally, for an integer array , an integer and a non-negative integer , an insertion operation on at position returns the array . An edit operation on is one of an insertion, a deletion or a substitution at a single position.

Given two integer arrays and , compute the minimum number of edit operations on to obtain an array satisfying .

For example, let and . Consider the array . Then, we have and therefore and are CP-equivalent. Then, we can obtain the integer array applying two edit operations on and it is minimum.

输入格式

Your program is to read from standard input. The input consists of three lines. The first line consists of two integers and (; ) that indicate the length of and , respectively. The second line consists of integers between and (both inclusive), representing the array . The third line consists of integers between and (both inclusive), representing the array .

输出格式

Your program is to write to standard output. Print exactly one line containing the minimum number of edit operations on to obtain an integer array satisfying .

样例

样例输入 1

5 5
64 2 5 100 100
3 1 2 4 1

样例输出 1

0

样例输入 2

5 4
64 2 5 100 100
-5 -5 -5 -5

样例输出 2

2

样例输入 3

6 5
1 2 3 4 5 6
2 5 3 4 5

样例输出 3

3

样例输入 4

6 3
1 3 5 2 5 2
5 5 6

样例输出 4

3