#K93252. Maximum Projects Assignment

    ID: 38378 Type: Default 1000ms 256MiB

Maximum Projects Assignment

Maximum Projects Assignment

In this problem, you are given T test cases. For each test case, there are N teams and M projects. Each team has a certain capability and each project has a minimum required capability. A team can be assigned at most one project, and a project can be assigned to a team only if that team's capability is greater than or equal to the project's requirement.

Formally, for each test case you are given two arrays: one of team capabilities (a₁, a₂, ..., a_N) and one of project requirements (b₁, b₂, ..., b_M). You need to determine the maximum number of projects that can be assigned such that for an assigned pair (team, project), the team’s capability is at least the project’s requirement.

The greedy strategy to solve this problem is as follows:

  1. Sort the team capabilities in non‐increasing order.
  2. Sort the project requirements in non‐decreasing order.
  3. Use two pointers to assign projects to teams in a greedy manner.

All formulas are provided in (\LaTeX) format. For example, given arrays (a_1, a_2, \ldots, a_N) and (b_1, b_2, \ldots, b_M), a team can be assigned to a project if (a_i \ge b_j).

inputFormat

The input begins with an integer (T) representing the number of test cases. Each test case consists of three lines:

  • The first line contains two integers (N) and (M) separated by a space, which represent the number of teams and the number of projects respectively.
  • The second line contains (N) space-separated integers representing the capabilities of the teams.
  • The third line contains (M) space-separated integers representing the minimum required capabilities for the projects.

outputFormat

For each test case, print a single integer on a new line denoting the maximum number of projects that can be assigned, following the rule that a team can only be assigned a project if its capability is at least the project's requirement.## sample

2
3 3
3 2 1
2 2 2
2 2
1 2
2 1
2

1

</p>