#P3254. 圆桌问题

    ID: 2303 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>Special Judge最大流网络流 24 题

圆桌问题

Description

There are representatives from mm different units attending an international conference. The ii-th unit sends rir_i representatives.

The conference restaurant has nn tables, and the ii-th table can seat cic_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 mm and the number of tables nn. The second line contains mm integers separated by spaces, where the ii-th integer represents the number of representatives rir_i in the ii-th unit. The third line contains nn integers separated by spaces, where the ii-th integer represents the capacity cic_i of the ii-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 00 or 11. Output 11 if a valid arrangement exists; otherwise, output 00. If it exists, then for lines 22 to (m+1)(m + 1), on line (i+1)(i + 1) output rir_i integers, representing the table indices where the representatives of the ii-th unit will dine.

4 5
4 5 3 5
3 5 2 6 4

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

Hint

  • Constraints:
    • For 100%100\% of the testdata, 1m1501 \leq m \leq 150, 1n2701 \leq n \leq 270, 1ri,ci1031 \leq r_i, c_i \leq 10^3.
  • Hint:
    • Note that the first line of input reads mm first, then nn.

Translated by ChatGPT 5