#P3254. International Conference Seating Arrangement

    ID: 16511 Type: Default 1000ms 256MiB

International Conference Seating Arrangement

International Conference Seating Arrangement

There are representatives from \(m\) different organizations attending an international conference. The \(i\)-th organization sends \(r_i\) representatives.

The conference restaurant has \(n\) tables. The \(j\)-th table has a capacity of \(c_j\) persons.

To promote communication, no two representatives from the same organization are allowed to dine at the same table. Your task is to produce a seating arrangement that satisfies these requirements.

Note:

  • For each organization, its representatives must be seated at different tables (i.e. at most one representative per table).
  • For each table, the total number of seated representatives cannot exceed its capacity \(c_j\).
  • You may assume that a valid seating arrangement exists.
  • inputFormat

    The input is given as follows:

     m n
     r1 r2 ... rm
     c1 c2 ... cn
    

    Where:

    • \(m\) is the number of organizations.
    • \(n\) is the number of tables.
    • \(r_i\) is the number of representatives from organization \(i\) (1-based).
    • \(c_j\) is the capacity of table \(j\) (1-based).

    outputFormat

    Output \(n\) lines. The \(j\)-th line describes the seating for table \(j\) in the following format:

     k a1 a2 ... ak
    

    Where \(k\) is the number of representatives seated at table \(j\) and each \(a_l\) is the 1-based index of the organization of a seated representative. If no one is seated at a table, output a line containing 0.

    sample

    3 3
    2 1 1
    2 1 1
    2 1 2
    

    1 1 1 3

    </p>