QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB Total points: 100

#127. 卡牌游戏策略

Statistics

Alice 和 Bob 正在玩一个卡牌游戏。共有 $n$ 张卡牌,每张卡牌上写有一个整数。 游戏过程如下:

  1. Alice 在 $a$ 到 $b$(包含 $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 在做出选择时,已知 Bob 对于给定的 $t$ 一定会最小化 $|t - u|$。此外,假设在有多个同样最优的选择时,Alice 倾向于选择较小的 $t$。

你的任务是确定游戏的结果:Alice 将选择的 $t$ 的值,以及 Bob 为该 $t$ 所选择的 $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, \dots, 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.