#C8503. Maximize Group Seating

    ID: 52493 Type: Default 1000ms 256MiB

Maximize Group Seating

Maximize Group Seating

In this problem, you are given two lists: one representing the capacities of tables and another representing the sizes of customer groups. Your task is to assign groups to tables such that a group is only seated at a table if the table's capacity is at least as large as the group size. Each table can seat at most one group. The goal is to maximize the number of seated groups.

A formal description: Given two arrays, (T = [t_1,t_2,\dots,t_n]) for table capacities and (G = [g_1,g_2,\dots,g_m]) for group sizes, you need to choose a set of pairs ((i,j)) (with table index and group index) such that (t_i \ge g_j) and no table or group appears more than once. Return the maximum number of groups that can be seated along with the list of assignment pairs.

Note: If there are multiple solutions, any valid seating plan is acceptable.

inputFormat

The first line contains two integers (n) and (m), representing the number of tables and groups respectively. The second line contains (n) space-separated integers representing the capacities of the tables. The third line contains (m) space-separated integers representing the sizes of the groups.

outputFormat

The first line should contain a single integer representing the maximum number of groups that can be seated. Each of the following lines should contain two integers separated by a space denoting the table index and the group index for each assignment.## sample

4 5
2 4 3 6
1 4 3 2 5
4

1 1 3 4 2 3 4 2

</p>