QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#10831. 扑克牌

统计

Alice 和 Bob 正在玩纸牌游戏。他们每人都有 $n$ 张牌,每张牌上都有一个数字。他们将进行 $n$ 轮游戏,每一轮中,每位玩家都要打出一张之前未出过的牌。在每一轮中,Alice 和 Bob 各出一张牌,并比较牌上的数字,数字较大者获胜。如果两张牌上的数字完全相同,则该轮平局。

Alice 的好胜心很强,她不想在任何一轮中输掉比赛。如果她在某一轮发现自己出的牌上的数字小于 Bob 出的牌上的数字,她就会进行多次作弊。每作弊一次,她可以将自己牌上的数字增加 $k$,她会在这一轮中持续作弊,直到她牌上的数字不小于 Bob 牌上的数字为止。

然而,作弊风险很高,因此她希望最小化作弊次数。为了实现这一目标,她设法获知了 Bob 将要出的牌的顺序,并且可以决定自己出牌的顺序。请帮她计算最少的作弊次数。

形式化地,我们可以用 $a_1, a_2, \dots, a_n$ 表示 Alice 手中的牌,用 $b_1, b_2, \dots, b_n$ 表示 Bob 将要出的牌的顺序。你需要找到一个 $n$ 的排列 $c_1, c_2, \dots, c_n$,使得 $$\sum_{i=1}^{n} \left\lceil \frac{\max(b_i - a_{c_i}, 0)}{k} \right\rceil$$ 最小化。你需要输出这个最小化后的值以及一个可能的序列 $c_1, c_2, \dots, c_n$。

输入格式

第一行包含两个整数 $n$ ($1 \le n \le 10^5$) 和 $k$ ($1 \le k \le 10^9$),分别表示每位玩家手中的牌数以及每次作弊增加的数值。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$),表示 Alice 手中的牌。

第三行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$),表示 Bob 出牌的顺序。注意 Bob 将按照该序列的顺序出牌。

输出格式

你需要输出两行。

第一行输出一个整数,表示最少的作弊次数。

第二行输出 $n$ 个整数 $c_1, c_2, \dots, c_n$,表示 Alice 为了最小化作弊次数而出的牌的顺序。即 Alice 在第 $i$ 轮出的牌是 $a_{c_i}$。如果有多种答案,输出任意一种即可。

样例

样例输入 1

4 2
2 7 6 4
3 9 1 8

样例输出 1

2
4 2 1 3

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.