P3253 [JLOI2013] Deleting Items
Description
Consider the following box redistribution problem:
1. There are $N$ items arranged into $M$ stacks.
2. All items are identical, but they have different priorities.
3. You may move only the top item of a stack.
4. 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.
5. Find the minimum number of moves needed to delete all items. Deletions do not count toward the move count.
6. This is a simplified version: no two items have the same priority, and $M = 2$.
Input Format
The first line contains two integers $N_1$, $N_2$ denoting the numbers of items in the two stacks, respectively. Then $N_1$ lines follow, giving the priorities in the first stack from top to bottom; larger numbers indicate higher priority. Then $N_2$ 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.
Explanation/Hint
Constraints:
$1 \le N_1 + N_2 \le 100000$, priorities $\le 10^7$.
Translated by ChatGPT 5