QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 1024 MB 總分: 100

#5430. 三角数

统计

在一个有 $N$ 名学生的班级里,到了进行演讲的强制性任务时间。大多数学生都非常兴奋,迫不及待地等待轮到自己。首先,他们必须被分成三个小组。第 1 组的学生将向第 2 组演讲,第 2 组向第 3 组演讲,第 3 组向第 1 组演讲。

这种分组的一个复杂之处在于学生的抱负水平不同。每名学生 $i$ 要求向至少 $A_i$ 个人演讲。因此,如果学生 $i$ 被分在第 1 组,那么第 2 组必须至少有 $A_i$ 名成员,学生 $i$ 才会感到满意。

图 1:该图对应第一个样例。

你的任务是根据学生的抱负水平,确定是否存在一种将学生分成三组的方法,使得每个人都感到满意;如果存在,请找出一个合法的分组方案。

输入格式

第一行包含一个整数 $N$ ($3 \le N \le 5 \cdot 10^5$),表示班级中的学生人数。 第二行包含 $N$ 个整数 $A_i$ ($1 \le A_i \le N$),其中 $A_i$ 表示第 $i$ 名学生想要演讲的最小人数。

输出格式

如果没有合法的分组方案,输出一行字符串 “NO”。 如果存在合法的分组方案,首先输出一行字符串 “YES”。然后,输出一行由字符 1、2 和 3 组成的字符串 $S$。该字符串中第 $i$ 个位置的字符表示第 $i$ 名学生所属的小组。如果存在多种方案,你可以输出其中任意一种。

子任务

你的解法将在多个测试用例组上进行测试。为了获得某一组的分数,必须通过该组中的所有测试用例。

组别 分值 数据范围
1 14 $A_1 = A_2 = \dots = A_N$
2 16 $N \le 10$
3 11 $A_i \le 3$
4 23 $N \le 3000$
5 36 无额外限制

样例

输入 1

10
1 3 1 3 3 2 4 1 5 2

输出 1

YES
3313332121

输入 2

3
1 2 2

输出 2

NO

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.