QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#441. 製作菜品

統計

廚師準備給小朋友們製作 $m$ 道菜,每道菜均使用 $k$ 克原材料。為此,廚師購入了 $n$ 種原材料,原材料從 $1$ 到 $n$ 編號,第 $i$ 種原材料的質量為 $d_i$ 克。$n$ 種原材料的質量之和恰好為 $m \times k$ 克,其中 $d_i$ 與 $k$ 都是正整數。

製作菜品時,一種原材料可以被用於多道菜,但為了讓菜品的味道更純粹,廚師打算每道菜至多使用 $2$ 種原材料。現在請你判斷是否存在一種滿足要求的製作方案。更具體地,方案應滿足下列要求:

  • 共做出 $m$ 道菜。
  • 每道菜至多使用 $2$ 種原材料。
  • 每道菜恰好使用 $k$ 克原材料。
  • 每道菜使用的每種原材料的質量都為正整數克。
  • $n$ 種原材料都被恰好用完。

若存在滿足要求的製作方案,你還應該給出一種具體的製作方案。

輸入格式

從檔案 dish.in 中讀入資料。

本題單個測試點包含多組測試資料。

第一行一個整數 $T$ 表示資料組數。對於每組資料:

  • 第一行三個正整數 $n, m, k$ 分別表示原材料種類數、需要製作的菜品道數、每道菜品需使用的原材料的質量。
  • 第二行 $n$ 個整數,第 $i$ 個整數表示第 $i$ 種原材料的質量 $d_i$。

輸出格式

輸出到檔案 dish.out 中。

對於每組測試資料:

  • 若不存在滿足要求的製作方案,則輸出一行一個整數 $-1$。
  • 否則你需要輸出 $m$ 行,每行表示一道菜品的製作方案,根據使用的原材料種類數,格式為下列兩種之一:

    • 依次輸出一行兩個整數 $i$ 和 $x$,表示該道菜使用 $x$ 克第 $i$ 種原材料製作。你應保證 $1 \le i \le n$,$x = k$。
    • 依次輸出一行四個整數 $i$、$x$、$j$ 和 $y$,表示該道菜使用 $x$ 克第 $i$ 種原材料與 $y$ 克第 $j$ 種原材料製作。你應保證 $1 \le i, j \le n$,$i \ne j$,$x + y = k$,$x, y > 0$。

本題使用自訂校驗器檢驗你的答案是否正確,因此若有多種滿足條件的方案,你只需要輸出任意一種。

你應保證方案輸出的格式正確,且同一行中相鄰的兩個數使用單個空格分隔,除此之外你的輸出中不應包含其他多餘字元。

範例

輸入格式 1

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

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

說明

對於第二組資料,一種滿足要求的製作方案為:

  • 使用 $80$ 克原材料 $1$ 與 $20$ 克原材料 $2$ 做第一道菜。
  • 使用 $10$ 克原材料 $2$ 與 $90$ 克原材料 $3$ 做第二道菜。
  • 使用 $100$ 克原材料 $4$ 做第三道菜。

範例 2

見選手目錄下的 dish/dish2.in 與 dish/dish2.ans。

範例 3

見選手目錄下的 dish/dish3.in 與 dish/dish3.ans。

資料範圍

對於所有測試點:

$1 \le T \le 10$,$1 \le n \le 500$,$n - 2 \le m \le 5000$,$m \ge 1$,$1 \le k \le 5000$,$\sum_{i=1}^{n} d_i = m \times k$。

每個測試點的具體限制見下表:

測試點編號 $n$ $m$ $k$
$1 \sim 3$ $\le 4$ $\le 4$ $\le 50$
$4 \sim 5$ $\le 10$ $\le 10$ $\le 5000$
$6 \sim 7$ $\le 500$ $= n - 1$
$8 \sim 9$ $n - 1 \le m \le 5000$
$10$ $\le 25$ $\le 5000$
$11 \sim 12$ $\le 500$
$13 \sim 14$ $\le 50$
$15 \sim 17$ $\le 100$ $\le 5000$
$18 \sim 20$ $\le 500$

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.