33OJ
登录 注册

#P17768. 「LDOI R2」卡牌 / Cards

    ID: 20373 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度暂无评定 上传者: 标签>洛谷原创Special JudgeO2优化洛谷月赛

「LDOI R2」卡牌 / Cards

Problem Description

There are mm players participating in a card game.

Each player holds one card for each number from 00 to nn (n≥mn \ge m). In each round of the game, every player plays one card, with the requirement that the sum of all played card numbers in that round must equal nn. Each card can be used by a player only once. The game ends when no valid card combination can satisfy the round's sum requirement.

Determine the maximum number of rounds they can play and provide a feasible playing strategy.

Input Format

There are multiple test cases for this problem.

The first line contains a positive integer TT, representing the number of test cases.

The next TT lines each contain two positive integers nn and mm.

Output Format

For each test case:

  • The first line contains a positive integer kk, representing the maximum number of rounds.
  • The following kk lines each contain mm numbers, representing the cards played by each player in that round. Any valid solution is acceptable.
3
2 2
10 3
8 5
3
0 2
2 0
1 1
7
0 3 7
8 2 0
1 8 1
5 1 4
3 4 3
4 0 6
2 6 2
4
0 3 4 0 1
4 1 2 1 0
1 2 1 2 2
2 0 0 3 3

Hint

Explanation

In the first test case, the output's second through fourth lines show the cards played by the two players across 33 rounds, where each round's card numbers sum to 22. It can be proven that the maximum number of possible rounds is indeed 33.

Constraints

This problem uses subtask scoring.

The output may be large, please use fast output methods.

Subtask Conditions Score
1 n≤5n \le 5 1010
2 n≤103n \le 10^3 2020
3 mm is even 1010
4 m=3m = 3 2020
5 None 4040

For all test cases, 2≤n≤1052 \le n \le 10^5, 2≤m≤1032 \le m \le 10^3, m≤nm \le n, 1≤T≤201 \le T \le 20.