#D. The Candy With Google and Tiny-Pang

    传统题 1000ms 256MiB

The Candy With Google and Tiny-Pang

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

说明

Google and Tiny-Pang have $n$ and $m$ candies in their hands respectively. The size of each candy is different. They use a container to hold the candy, and imagine that the candy in the container is from bottom to top.

Google and Tiny-Pang want to eat these candies now. They can only eat the biggest candy of all each time, but only the candy at the top of the two containers can be eaten. As we all know, Google and Tiny-Pang is smart enough, Google and Tiny-Pang can steal a candy at the top of one container to another at a time. The question is how many times do they need to steal at least to make all the candy eaten?

输入格式

The first line contains two integers $n, m$ $(1\leq n + m \leq 5 \times 10^5)$, represent the number of candies in the two piles.

The first integer in next two lines represents the size of the candy at the top of the container.

The second line contains $n$ integers $a_1,a_2,...,a_n$ $(1\leq a_i \leq 5 \times 10^5)$, represent each size of candy in Google's container.

The third line contains $m$ integers $b_1,b_2,...,b_m$$(1\leq b_i \leq 5 \times 10^5)$, represent each size of candy in Tiny-Pang container.

输出格式

Print the minimum times that all candies can be eaten.

样例

3 3
1 4 5
2 7 3
6

样例

1 9
57
78 27 88 73 47 85 20 16 94 
21

提示

For the first sample,

- Move the 2 to the first container, need 1 step. Then the 7 was eaten.

- Move the 2,1,4 to the second container, need 3 steps. Then the 5 was eaten.

- The 4 is largest and in the top, need 0 step. Then the 4 was eaten.

- Move the 1,2 to the second container, need 2 steps. Then the 3 was eaten.

- The 2 is largest and in the top, need 0 step. Then the 2 was eaten.

- The 1 is largest and in the top, need 0 step. Then the 1 was eaten.

福建师范大学第十八届程序设计竞赛正式赛

未参加
状态
已结束
规则
IOI
题目
10
开始于
2022-4-25 8:00
结束于
2023-3-24 16:00
持续时间
8000 小时
主持人
参赛人数
15