루미 알고리즘

#1536플래티넘Triangle numbers

PO 2022 결선코딩출제 Nils Gustafsson영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

In a class with N students, it is time for the obligatory task of giving a speech. Most students are very excited to give their speeches and can hardly wait for their turn. First, they must be divided into three groups. Everyone in group 1 will then present to group 2, group 2 to group 3, and group 3 to group 1.

One complication in this grouping is that the students have different ambition levels. Each student i requires to give their speech to at least A_i people. So, if student i ends up in group 1, group 2 must have at least A_i members for student i to be satisfied.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: The image corresponds to the first example.

Your task is to determine, given the students' ambition levels, if there is a way to divide the students into three groups so that everyone is satisfied, and if so, find a valid division.

Input

The first line contains an integer N (3 ≤ N ≤ 5 · 10^5), the number of students in the class.

The second line contains N integers A_i (1 ≤ A_i ≤ N), where A_i is the minimum number of students the i-th student wants to give a speech to.

Output

If there is no valid division, print a single line with the string “NO”.

If there is a valid division, first print a line with the string “YES”. Then, print a line with a string S consisting of the characters 1, 2, and 3. The character at position i in this string indicates which group student i belongs to. If there are multiple solutions, you can print any of them.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

GroupPointsConstraints
114A_1 = A_2 = … = A_N
216N ≤ 10
311A_i ≤ 3
423N ≤ 3000
536No additional constraints.

예제

예제 1

입력
10
1 3 1 3 3 2 4 1 5 2
출력
YES
3313332121

예제 2

입력
3
1 2 2
출력
NO

출처 표기

출처: Programmeringsolympiaden 2022년 결선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.