QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 1024 MB 満点: 100 難易度: [表示] ハック可能 ✓

#127. 卡牌遊戲策略

統計

Alice 和 Bob 準備玩一個卡牌遊戲。共有 $n$ 張牌,每張牌上都寫有一個整數。遊戲按如下步驟進行:

  1. Alice 在 $a$ 到 $b$ 之間(包含兩端)選擇一個整數。稱這個整數為 $t$。然後 Alice 將 $t$ 的值告訴 Bob。
  2. Bob 從這 $n$ 張牌中選擇 $k$ 張牌。計算 Bob 所選的 $k$ 張牌上所寫整數之和。稱這個和為 $u$。

Alice 的目標是使 $|t - u|$ 盡可能大,而 Bob 的目標是使 $|t - u|$ 盡可能小。在遊戲開始之前,Alice 和 Bob 都知道 $n$、$k$、$a$ 和 $b$ 的值,也知道所有牌上的整數。Alice 和 Bob 都會採取最佳策略。特別地,Alice 在做出選擇時知道,對於她所告知的 $t$,Bob 一定會使 $|t - u|$ 最小化。此外,假設當 Alice 有多個同樣好的選擇時,她傾向於選擇較小的 $t$。

你的任務是確定遊戲的結果:Alice 會選擇的 $t$ 的值,以及對於該 $t$,Bob 會選擇的 $k$ 張牌。

輸入格式

輸入包含兩行,表示單一測試資料。第一行包含四個整數 $n$、$k$、$a$ 和 $b$($1 \le k \le n \le 600$,$0 \le a \le b \le 1.8 \cdot 10^5$)。第二行包含 $n$ 個整數 $x_1, \ldots, x_n$($0 \le x_i \le 300$),表示第 $i$ 張牌上寫著 $x_i$。

輸出格式

輸出兩行:第一行應包含一個整數,表示 Alice 會選擇的 $t$ 的值。第二行應包含 $k$ 個介於 $1$ 到 $n$ 之間(包含兩端)的相異整數,表示 Bob 會選擇的牌的編號。如果 Bob 有多個同樣好的選擇,輸出其中任意一個即可。

範例

輸入格式 1

4 2 58 100
10 10 50 80

輸出格式 1

75
2 3

輸入格式 2

8 3 1300 1800
2 0 1 5 0 4 1 9

輸出格式 2

1800
4 6 8

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.