QOJ.ac

QOJ

时间限制: 5 s 内存限制: 512 MB 总分: 100

#3321. 第六感

统计

Ms. Future 拥有预知未来的天赋。自然地,她擅长某些纸牌游戏,因为她能准确预见除自己以外每一位玩家的行动。今天,她接受了鲁莽的赌徒 Mr. Past 的挑战。他们约定进行一种简单的双人吃墩纸牌游戏。

游戏用的纸牌一面印有数字,另一面为空白,使得纸牌之间无法区分。

游戏开始时,双方各分到相同数量(设为 $n$)的牌,且不向对手透露牌面数字。

游戏包含 $n$ 轮。在每一轮中,双方各出一张牌。出牌数字较大的玩家赢得该轮。由于 Ms. Future 非常擅长此游戏,他们约定当双方出的牌数字相同时,由 Mr. Past 赢得该轮。牌一旦使用,在同一局游戏中就不能再次使用。游戏持续到双方手中的牌全部用完。游戏的目标是尽可能多地赢得轮次。

本题的任务是帮助 Ms. Future,通过编写程序来确定她手中牌的最佳出牌顺序。由于她拥有第六感,你的程序可以利用在游戏开始前普通人无法获得的信息。

输入格式

输入包含一组测试数据,格式如下:

$n$ $p_1 \dots p_n$ $f_1 \dots f_n$

第一行的 $n$ 是轮数,为一个介于 $2$ 到 $5000$ 之间的整数(包含边界)。第二行代表 Mr. Past 的出牌顺序。在第 $i$ 轮中,他将出一张数字为 $p_i$ ($1 \le i \le n$) 的牌。第三行代表 Ms. Future 手中的牌。$f_i$ ($1 \le i \le n$) 是她从发牌员处收到的第 $i$ 张牌上的数字。第二行或第三行中的每个数字都是介于 $1$ 到 $10\,000$ 之间的整数(包含边界)。这些行中可能包含重复数字。

输出格式

输出应为一行,包含 $n$ 个由空格分隔的整数 $a_1 \dots a_n$,其中 $a_i$ ($1 \le i \le n$) 是她为了最大化赢得轮次而在第 $i$ 轮应出的牌的数字。如果存在多个这样的序列,输出其中字典序最大的一个。

样例

样例输入 1

5
1 2 3 4 5
1 2 3 4 5

样例输出 1

2 3 4 5 1

样例输入 2

5
3 4 5 6 7
1 3 5 7 9

样例输出 2

9 5 7 3 1

样例输入 3

5
3 2 2 1 1
1 1 2 2 3

样例输出 3

1 3 1 2 2

样例输入 4

5
3 4 10 4 9
2 7 3 6 9

样例输出 4

9 7 3 6 2

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.