P3254 Round Table Problem
Description
There are representatives from $m$ different units attending an international conference. The $i$-th unit sends $r_i$ representatives.
The conference restaurant has $n$ tables, and the $i$-th table can seat $c_i$ representatives.
To encourage communication, representatives from the same unit should not dine at the same table. Please provide a dining arrangement that satisfies this requirement.
Input Format
The first line contains two integers separated by a space, representing the number of units $m$ and the number of tables $n$.
The second line contains $m$ integers separated by spaces, where the $i$-th integer represents the number of representatives $r_i$ in the $i$-th unit.
The third line contains $n$ integers separated by spaces, where the $i$-th integer represents the capacity $c_i$ of the $i$-th table.
Output Format
This problem uses Special Judge.
Output whether a valid arrangement exists. If it exists, output any valid arrangement.
The first line contains a single integer, either $0$ or $1$. Output $1$ if a valid arrangement exists; otherwise, output $0$.
If it exists, then for lines $2$ to $(m + 1)$, on line $(i + 1)$ output $r_i$ integers, representing the table indices where the representatives of the $i$-th unit will dine.
Explanation/Hint
- Constraints:
- For $100\%$ of the testdata, $1 \leq m \leq 150$, $1 \leq n \leq 270$, $1 \leq r_i, c_i \leq 10^3$.
- Hint:
- Note that the first line of input reads $m$ first, then $n$.
Translated by ChatGPT 5