#K52797. Maximum Stamps Placement in the Album
Maximum Stamps Placement in the Album
Maximum Stamps Placement in the Album
Alice has an album with (n) pages and she owns (m) stamps. Each album page has a slot capacity defined by an array (pages = [p_1, p_2, \dots, p_n]) and each stamp has a slot requirement given in the array (stamps = [s_1, s_2, \dots, s_m]). A stamp can be placed on a page if and only if the page's capacity is greater than or equal to the stamp's requirement. Each page can hold at most one stamp. Your task is to determine the maximum number of stamps that can be placed in the album.
The problem can be solved by sorting both arrays and then using a two-pointer technique to greedily assign stamps to pages such that for a page (p_i) and a stamp (s_j), if (p_i \ge s_j), we place the stamp and move to the next stamp and page. Otherwise, we move to the next page.
inputFormat
The input is read from standard input and consists of three lines.
The first line contains two integers (n) and (m) where (n) is the number of pages and (m) is the number of stamps.
The second line contains (n) space-separated integers representing the capacities of each page.
The third line contains (m) space-separated integers representing the slot requirements of each stamp.
outputFormat
Output a single integer, the maximum number of stamps that can be placed in the album, printed to standard output.## sample
3 4
10 20 30
5 10 15 20
3