#P8800. [蓝桥杯 2022 国 B] 卡牌

[蓝桥杯 2022 国 B] 卡牌

Problem Description

On this day, Xiaoming is organizing his cards.

He has a total of nn types of cards. On the ii-th type of card, a positive integer i (i[1,n])i \ (i \in [1, n]) is printed, and he currently has aia_{i} cards of type ii.

If there are nn cards with exactly one card of each type, then these nn cards are called one set. In order to make as many sets as possible, Xiaoming takes out mm blank cards. He can write the number ii on a blank card and treat it as a card of type ii to form sets. However, Xiaoming feels that handwritten cards do not look nice, so he decides to handwrite at most bib_{i} cards of type ii.

Please find the maximum number of sets Xiaoming can form.

Input Format

The input has 3 lines.

The first line contains two positive integers nn and mm.

The second line contains nn positive integers a1,a2,,ana_{1}, a_{2}, \ldots, a_{n}.

The third line contains nn positive integers b1,b2,,bnb_{1}, b_{2}, \ldots, b_{n}.

Output Format

One line with one integer representing the answer.

4 5
1 2 3 4
5 5 5 5
3

Hint

[Sample Explanation]

Among these 55 blank cards, take 22 cards to write 11, and take 11 card to write 22. Then the number of each type of card becomes 3,3,3,43, 3, 3, 4, so you can form 33 sets. The remaining 22 blank cards can no longer help Xiaoming form another set.

[Test Case Scale and Assumptions]

For 30%30\% of the testdata, it is guaranteed that n2000n \leq 2000.

For 100%100\% of the testdata, it is guaranteed that $n \leq 2 \times 10^{5}; \ a_{i}, b_{i} \leq n; \ m \leq n^{2}$.

Lanqiao Cup 2022 National Contest Group B, Problem C.

Translated by ChatGPT 5