#P3253. [JLOI2013] 删除物品
[JLOI2013] 删除物品
Description
Consider the following box redistribution problem:
- There are items arranged into stacks.
- All items are identical, but they have different priorities.
- You may move only the top item of a stack.
- You may move the top item of any stack onto the top of another stack. If this item is currently the highest-priority among all items, you may delete it immediately instead of moving it.
- Find the minimum number of moves needed to delete all items. Deletions do not count toward the move count.
- This is a simplified version: no two items have the same priority, and .
Input Format
The first line contains two integers , denoting the numbers of items in the two stacks, respectively. Then lines follow, giving the priorities in the first stack from top to bottom; larger numbers indicate higher priority. Then lines follow in the same format for the second stack.
Output Format
For the given testdata, output a single integer, the minimum number of moves.
3 3
1
4
5
2
7
3
6
Hint
Constraints: , priorities .
Translated by ChatGPT 5
京公网安备 11011102002149号