QOJ.ac

QOJ

実行時間制限: 6 s メモリ制限: 512 MB 満点: 100

#10604. 公平分配

統計

Bajtyna 和 Bitek 需要分配 $n$ 个物品。对于每个物品,我们已知它对 Bajtyna 的价值以及它对 Bitek 的价值;这两个价值可能相同,也可能不同。我们希望将每个物品恰好分配给一个人,使得没有任何人嫉妒另一个人,嫉妒的定义如下:

Bitek 嫉妒 Bajtyna,当且仅当 Bitek 所拥有的所有物品的价值总和(按 Bitek 的价值计算)严格小于 Bajtyna 所拥有的所有物品中去掉任意一个物品后的价值总和(按 Bitek 的价值计算)。特别地,如果 Bajtyna 拥有的物品中包含价值最小的物品,则去掉该物品。例如,考虑四个物品,其对 Bitek 的价值分别为 $4, 3, 4, 8$。如果将前两个物品分配给 Bitek,则 Bitek 嫉妒 Bajtyna,因为 $4 + 3 < 8$。如果将最后一个物品分配给 Bitek,则 Bitek 不嫉妒 Bajtyna,因为 $8 \ge 4 + 4$。

我们以类似的方式定义 Bajtyna 何时嫉妒 Bitek,此时我们通过计算对 Bajtyna 的价值总和来进行比较。

请将所有物品在 Bajtyna 和 Bitek 之间进行分配,使得没有任何人嫉妒另一个人。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 500\,000$),表示物品的数量。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$),表示每个物品对 Bajtyna 的价值。 第三行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$),表示每个物品对 Bitek 的价值。

输出格式

第一行输出 $n$ 个由空格分隔的整数,描述满足题目条件的物品分配方案。其中第 $i$ 个数应为 $0$(如果第 $i$ 个物品分配给 Bajtyna)或 $1$(如果分配给 Bitek)。你可以假设总是存在满足条件的分配方案。

样例

输入格式 1

4
10 5 9 6
4 6 8 4

输出格式 1

1 0 0 1

说明

Bajtyna 获得了第二个和第三个物品,Bitek 获得了其余物品。Bajtyna 不嫉妒 Bitek,因为 $5 + 9 \ge 10$ 且 $5 + 9 \ge 6$。Bitek 不嫉妒 Bajtyna,因为 $4 + 4 \ge 6$ 且 $4 + 4 \ge 8$。

评分

子任务 限制 分值
1 $n \le 10$ 9
2 $n \le 20$ 10
3 对所有 $i$,$a_i = b_i$ 40
4 $n \le 1000$ 15
5 无额外限制 26

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.