#P6775. [NOI2020] 制作菜品

[NOI2020] 制作菜品

Description

A chef plans to cook mm dishes for kids, and each dish uses kk grams of ingredients. For this purpose, the chef bought nn types of ingredients, numbered from 11 to nn. The mass of ingredient type ii is did_i grams. The total mass of all nn ingredients is exactly m×km \times k grams, where both did_i and kk are positive integers.

When cooking, one type of ingredient may be used in multiple dishes. However, to make the taste purer, the chef decides that each dish uses at most 22 types of ingredients. Now you need to determine whether there exists a cooking plan that satisfies the requirements. More specifically, the plan must satisfy:

  • A total of mm dishes are made.
  • Each dish uses at most 22 types of ingredients.
  • Each dish uses exactly kk grams of ingredients.
  • The amount of each ingredient used in each dish is a positive integer number of grams.
  • All nn types of ingredients are used up exactly.

If such a plan exists, you also need to output one specific plan.

Input Format

This problem contains multiple test cases in a single test file.

The first line contains an integer TT denoting the number of test cases. For each test case:

  • The first line contains three positive integers n,m,kn, m, k, representing the number of ingredient types, the number of dishes to cook, and the grams of ingredients needed per dish.
  • The second line contains nn integers; the ii-th integer denotes did_i, the mass of ingredient type ii.

Output Format

For each test case:

  • If no feasible cooking plan exists, output one line with the integer 1-1.
  • Otherwise, output mm lines, each describing one dish. Depending on how many ingredient types are used, the format is one of the following:
    • Output two integers ii and xx, meaning this dish uses xx grams of ingredient type ii. You must ensure 1in1 \leq i \leq n and x=kx = k.
    • Output four integers ii, xx, jj, and yy, meaning this dish uses xx grams of ingredient type ii and yy grams of ingredient type jj. You must ensure 1i,jn1 \leq i, j \leq n, iji \not= j, x+y=kx + y = k, and x,y>0x, y > 0.

This problem uses a custom checker to verify your output, so if multiple valid plans exist, you only need to output any one of them.

You must ensure the output format is correct. Adjacent numbers on the same line must be separated by exactly one space, and your output must not contain any other extra characters.

4
1 1 10
10
4 3 100
80 30 90 100
5 3 1000
200 400 500 900 1000
6 4 100
25 30 50 80 95 120
1 10
1 80 2 20
2 10 3 90
4 100
-1
1 5 5 95
1 20 4 80
2 30 6 70
3 50 6 50

Hint

Sample 1 Explanation

For the second test case, one feasible cooking plan is:

  • Use 8080 grams of ingredient 11 and 2020 grams of ingredient 22 to make the first dish.
  • Use 1010 grams of ingredient 22 and 9090 grams of ingredient 33 to make the second dish.
  • Use 100100 grams of ingredient 44 to make the third dish.

Sample 2

See dish/dish2.in and dish/dish2.ans in the contestant directory.

Sample 3

See dish/dish3.in and dish/dish3.ans in the contestant directory.


Constraints

For all test cases: 1T101 \leq T \leq 10, 1n5001 \leq n \leq 500, n2m5000n - 2 \leq m \leq 5000, m1m \geq 1, 1k50001 \leq k \leq 5000, i=1ndi=m×k\sum_{i=1}^{n}d_i = m \times k.

The specific limits for each test point are shown in the table below:

Test Point ID nn mm kk
131\sim 3 4\le 4 50\le 50
454\sim 5 10\le 10 5×103\le 5\times 10^3
676\sim 7 500\le 500 =n1=n-1
898\sim 9 n1m5×103n-1\le m\le 5\times 10^3
1010 25\le 25 5×103\le 5\times 10^3
111211\sim 12 500\le 500
131413\sim 14 50\le 50
151715\sim 17 100\le 100 5×103\le 5\times 10^3
182018\sim 20 500\le 500

Translated by ChatGPT 5