luogu#P3254. 圆桌问题

    ID: 7284 Type: RemoteJudge 1000ms 125MiB Tried: 32 Accepted: 4 Difficulty: 7 Uploaded By: Tags>Special JudgeO2优化网络流 24 题

圆桌问题

Problem 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