P8109 [Cnoi2021] Gensokyo Programming Contest

Background

Gensokyo, spring. The land of the new year sprouts tender new buds, and the 1st Inner-Gensokyo Programming Contest (IGPC) begins. As the organizer, Cirno has something she must think about. That is the problem of distributing balloons.

Description

There are $n$ problems in this contest. Cirno has accurately predicted the number of teams that will get AC for each problem: $a_1,a_2,a_3,\cdots,a_n$. But due to budget limits, the organizer has prepared only $b_1,b_2,b_3,\cdots,b_n$ balloons for the $n$ different colors. Cirno needs to arrange the balloon color corresponding to each problem reasonably, so that as many balloons as possible can be handed out. Obviously, each problem can correspond to only one color of balloon, and each color of balloon can correspond to only one problem. If a team solves a problem but the balloons of that color have already run out, then unfortunately, that team cannot get that balloon. Since this problem is too trivial, Cirno decides to assign this task to you.

Input Format

The first line contains an integer $n$. The second line contains $n$ integers separated by spaces, representing $\{a_n\}$. The third line contains $n$ integers separated by spaces, representing $\{b_n\}$.

Output Format

Output one line containing one integer, representing the maximum number of balloons that can be handed out.

Explanation/Hint

**Constraints and Notes** For $100\%$ of the testdata, it is guaranteed that $1 \le n \le 10^5$, $0 \le a_i,b_i \le 10^4$, and $\{a_n\},\{b_n\}$ are non-decreasing. **Subtasks** Subtask 1 ($60$ points): $n \le 8$. Subtask 2 ($40$ points): No special constraints. Translated by ChatGPT 5