All problems

Problem 243

Assign Cookies

Easy · 10 pts · Array, Greedy, Sorting

Problem

You want to give cookies to N children. Child i is content only with a cookie of size at least G[i] (their greed factor). You have M cookies, and cookie j has size S[j]. Each child gets at most one cookie, and each cookie goes to at most one child. Find the maximum number of children you can make content. Sort both lists. Then give the smallest cookies to the least greedy children first: walk through the cookies in increasing size, and whenever the current cookie satisfies the least greedy unsatisfied child, give it to that child.

Input

First line: N. Second line: N greed values. Third line: M. Fourth line: M cookie sizes.

Output

Print the maximum number of content children.

Constraints

1 <= N, M <= 30000; 1 <= G[i], S[j] <= 1000000000

Example input

3
1 2 3
2
1 1

Example output

1

Explanation

The children have greed 1, 2 and 3, and both cookies have size 1. A size-1 cookie can only satisfy the child with greed 1, so only 1 child can be made content.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Hamming Distance Next: Lemonade Change