#K58432. Max Friends Attend Concert

    ID: 30641 Type: Default 1000ms 256MiB

Max Friends Attend Concert

Max Friends Attend Concert

Given a group of friends and a set of available ticket prices, determine the maximum number of friends who can attend the concert. Each friend can purchase at most one ticket, and a friend can only buy a ticket if the amount of money they have is greater than or equal to the ticket price.

Formally, you are given two lists: one representing the money each friend has, and another representing the available ticket prices. Let \( arr \) be a list of \( n \) integers and \( prices \) be a list of \( m \) integers. We need to find the maximum number of pairs such that for each pair, \( arr[i] \geq prices[j] \). A greedy approach where both lists are sorted and then matched using a two-pointer technique will yield the solution.

inputFormat

The input is read from stdin and has the following format:

n m
arr[0] arr[1] ... arr[n-1]
prices[0] prices[1] ... prices[m-1]
  • \( n \) is the number of friends.
  • \( m \) is the number of available ticket prices.
  • arr is a list of \( n \) integers representing the amount of money each friend has.
  • prices is a list of \( m \) integers representing the ticket prices.

outputFormat

Output a single integer to stdout representing the maximum number of friends that can attend the concert.

## sample
5 3
20 15 30 10 50
10 25 50
3

</p>