luogu#P8109. [Cnoi2021] 幻想乡程序设计大赛

[Cnoi2021] 幻想乡程序设计大赛

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.

Problem Description

There are nn problems in this contest. Cirno has accurately predicted the number of teams that will get AC for each problem: a1,a2,a3,,ana_1,a_2,a_3,\cdots,a_n. But due to budget limits, the organizer has prepared only b1,b2,b3,,bnb_1,b_2,b_3,\cdots,b_n balloons for the nn 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 nn.

The second line contains nn integers separated by spaces, representing {an}\{a_n\}.

The third line contains nn integers separated by spaces, representing {bn}\{b_n\}.

Output Format

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

5
1 2 3 4 5
2 3 3 3 3
12

Hint

Constraints and Notes

For 100%100\% of the testdata, it is guaranteed that 1n1051 \le n \le 10^5, 0ai,bi1040 \le a_i,b_i \le 10^4, and {an},{bn}\{a_n\},\{b_n\} are non-decreasing.

Subtasks

Subtask 1 (6060 points): n8n \le 8.

Subtask 2 (4040 points): No special constraints.

Translated by ChatGPT 5