311344: CF1972A. Contest Proposal

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Contest Proposaltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

A contest contains $n$ problems and the difficulty of the $i$-th problem is expected to be at most $b_i$. There are already $n$ problem proposals and the difficulty of the $i$-th problem is $a_i$. Initially, both $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$ are sorted in non-decreasing order.

Some of the problems may be more difficult than expected, so the writers must propose more problems. When a new problem with difficulty $w$ is proposed, the most difficult problem will be deleted from the contest, and the problems will be sorted in a way that the difficulties are non-decreasing.

In other words, in each operation, you choose an integer $w$, insert it into the array $a$, sort array $a$ in non-decreasing order, and remove the last element from it.

Find the minimum number of new problems to make $a_i\le b_i$ for all $i$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le 100$). The description of the test cases follows.

The first line of each test case contains only one positive integer $n$ ($1 \leq n \leq 100$), representing the number of problems.

The second line of each test case contains an array $a$ of length $n$ ($1\le a_1\le a_2\le\cdots\le a_n\le 10^9$).

The third line of each test case contains an array $b$ of length $n$ ($1\le b_1\le b_2\le\cdots\le b_n\le 10^9$).

Output

For each test case, print an integer as your answer in a new line.

ExampleInput
2
6
1000 1400 2000 2000 2200 2700
800 1200 1500 1800 2200 3000
6
4 5 6 7 8 9
1 2 3 4 5 6
Output
2
3
Note

In the first test case:

  • Propose a problem with difficulty $w=800$ and $a$ becomes $[800,1000,1400,2000,2000,2200]$.
  • Propose a problem with difficulty $w=1800$ and $a$ becomes $[800,1000,1400,1800,2000,2000]$.

It can be proved that it's impossible to reach the goal by proposing fewer new problems.

In the second test case:

  • Propose a problem with difficulty $w=1$ and $a$ becomes $[1,4,5,6,7,8]$.
  • Propose a problem with difficulty $w=2$ and $a$ becomes $[1,2,4,5,6,7]$.
  • Propose a problem with difficulty $w=3$ and $a$ becomes $[1,2,3,4,5,6]$.

It can be proved that it's impossible to reach the goal by proposing fewer new problems.

Output

题目大意:
一个比赛包含n个问题,第i个问题的难度预计最多为\( b_i \)。已经有n个问题提案,第i个问题的难度为\( a_i \)。最初,\( a_1, a_2, \ldots, a_n \)和\( b_1, b_2, \ldots, b_n \)都是按非递增顺序排序的。

一些问题可能比预期的更难,所以命题者必须提出更多的问题。当一个难度为w的新问题被提出时,比赛中最难的问题将被删除,并且问题将以难度非递增的方式排序。

换句话说,在每次操作中,你选择一个整数w,将其插入数组a中,将数组a按非递增顺序排序,并从其中删除最后一个元素。

求使\( a_i \leq b_i \)对所有i成立所需的新问题最小数量。

输入输出数据格式:
每个测试包含多个测试用例。第一行包含测试用例数\( t \)(\( 1 \leq t \leq 100 \))。接下来是测试用例的描述。

每个测试用例的第一行只包含一个正整数\( n \)(\( 1 \leq n \leq 100 \)),表示问题的数量。

每个测试用例的第二行包含一个长度为n的数组\( a \)(\( 1 \leq a_1 \leq a_2 \leq \cdots \leq a_n \leq 10^9 \))。

每个测试用例的第三行包含一个长度为n的数组\( b \)(\( 1 \leq b_1 \leq b_2 \leq \cdots \leq b_n \leq 10^9 \))。

对于每个测试用例,在新的一行中打印一个整数作为你的答案。题目大意: 一个比赛包含n个问题,第i个问题的难度预计最多为\( b_i \)。已经有n个问题提案,第i个问题的难度为\( a_i \)。最初,\( a_1, a_2, \ldots, a_n \)和\( b_1, b_2, \ldots, b_n \)都是按非递增顺序排序的。 一些问题可能比预期的更难,所以命题者必须提出更多的问题。当一个难度为w的新问题被提出时,比赛中最难的问题将被删除,并且问题将以难度非递增的方式排序。 换句话说,在每次操作中,你选择一个整数w,将其插入数组a中,将数组a按非递增顺序排序,并从其中删除最后一个元素。 求使\( a_i \leq b_i \)对所有i成立所需的新问题最小数量。 输入输出数据格式: 每个测试包含多个测试用例。第一行包含测试用例数\( t \)(\( 1 \leq t \leq 100 \))。接下来是测试用例的描述。 每个测试用例的第一行只包含一个正整数\( n \)(\( 1 \leq n \leq 100 \)),表示问题的数量。 每个测试用例的第二行包含一个长度为n的数组\( a \)(\( 1 \leq a_1 \leq a_2 \leq \cdots \leq a_n \leq 10^9 \))。 每个测试用例的第三行包含一个长度为n的数组\( b \)(\( 1 \leq b_1 \leq b_2 \leq \cdots \leq b_n \leq 10^9 \))。 对于每个测试用例,在新的一行中打印一个整数作为你的答案。

加入题单

上一题 下一题 算法标签: