Programs
InterviewTime limit12sMemory limit1024 MB
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 (), the number of programs.
The second line contains natural numbers () separated by single spaces, the sizes of the programs in bytes.
The third line contains a natural number (), the number of CDs.
The fourth line contains natural numbers () 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.