Under construction

Still being built. Things may change

Programs

Interview

Time limit12sMemory limit1024 MB

Summary
Given program sizes and CD capacities, find the most programs that can each be matched to a different CD with enough capacity.
Level

Easy3 of 10

Topics
Greedy, Sorting, Two pointers
Solved
No attempts yet

Problem

Bajtazar is replacing his computer and must move his software from the old machine to the new one. Because of security concerns, he will not send programs through the cloud or by email. He will copy them onto CDs instead.

Each CD holds at most one program, no matter how much free space remains on it. A program cannot be split across several CDs. Each program is written in one piece onto at most one CD.

Each program has a size, and each CD has a capacity. A program can be written to a CD only if its size is at most the capacity of that CD.

Bajtazar may not be able to move everything under these rules. Find the largest number of programs he can move while following them.

Input

The first line contains a natural number NN (1≤N≤1061 \le N \le 10^6), the number of programs.

The second line contains NN natural numbers AiA_i (1≤Ai≤1091 \le A_i \le 10^9) separated by single spaces, the sizes of the programs in bytes.

The third line contains a natural number MM (1≤M≤1061 \le M \le 10^6), the number of CDs.

The fourth line contains MM natural numbers BiB_i (1≤Bi≤1091 \le B_i \le 10^9) separated by single spaces, the capacities of the CDs in bytes.

Output

Print one integer, the largest number of programs that can be moved while following Bajtazar's rules.

Examples2

  1. Example 1

    Input
    5
    3 10 20 7 4
    4
    100 1 8 5
    
    Expected output
    3
    
  2. Example 2

    Input
    3
    42 34 21
    4
    9 20 18 7
    
    Expected output
    0