cswork / OA打开练习工作台

AmazonOA #269

Maximize Similarity

估计简单可在线判题

考点(AI 标注)位运算原地数组

You are given two arrays inv1 and inv2 of equal length. Any number of times, you may choose distinct i and j and, only when inv1[j]>0, take 1 from j and add 1 to i. Inventory may become 0 after the operations but never negative; inv2 does not change. The similarity is the number of indices whose values are equal in both arrays. Find the maximum similarity.

输入格式

The first line contains n, the second line contains inv1, and the third line contains inv2. 1≤n≤100000; every value in both initial arrays is in 1..10000.

输出格式

Output a single integer, the answer.

样例 1

输入:

3
1 1 1
4 4 4

输出:

0

样例 2

输入:

2
1 4
2 3

输出:

2

样例 3

输入:

3
10 1 1
1 1 1

输出:

2

样例说明

The answers are 0, 2 and 2 respectively. You cannot keep taking from a position whose inventory is 0, so in the first example the budget is not enough to match any 4; in the third example the extra total of 9 must go to at least one unmatched position.