#K75702. Maximizing Sector Energy Supply

    ID: 34478 Type: Default 1000ms 256MiB

Maximizing Sector Energy Supply

Maximizing Sector Energy Supply

In this problem, you are given (n) energy stations with capacities (S_1, S_2, \ldots, S_n) and (m) sectors with minimum energy requirements (R_1, R_2, \ldots, R_m). Each energy station can supply energy to at most one sector, and each sector requires energy from exactly one station where the station's capacity is at least the sector's minimum requirement.

To maximize the number of sectors that can be powered, a greedy strategy is effective: sort both the energy station capacities and sector requirements, then use a two-pointer technique to match the smallest available station that meets the current sector's requirement. Mathematically, if we denote the sorted energy capacities by (S_i) and the sorted requirements by (R_j), then we try to maximize the number of indices (j) for which there exists an (i) satisfying (S_i \ge R_j).

inputFormat

The input is read from standard input (stdin) and consists of three lines:

1. The first line contains two integers (n) and (m) separated by a space, representing the number of energy stations and sectors, respectively.
2. The second line contains (n) space-separated integers, where each integer represents the capacity of an energy station.
3. The third line contains (m) space-separated integers, where each integer represents the minimum energy requirement for a sector.

outputFormat

Output to standard output (stdout) a single integer: the maximum number of sectors that can receive the required energy.## sample

4 3
10 15 7 20
8 10 5
3