Logo
(追記) (追記ここまで)

6791번 - Reorganization 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB1544100.000%

문제

Alice and Bob own a huge company. This company was losing money consistently over the last 30 years, since its owners spent too much time playing games with mathematicians. Alice and Bob decide to make a change.

Alice and Bob start by giving unique employee IDs to each of the n employees (1 ≤ n ≤ 100, 000), where each ID I is in the range (1 ≤ I ≤ 100, 000).

Then, Alice and Bob give unique ranks to each employee. Each rank R is an integer such that 1 ≤ R ≤ 10, 000, 000. After this, they plan to reorganize the company, by making sure that the employees satisfy the following conditions:

  1. There is exactly one director, who has no supervisor;
  2. Except for the director, each employee has a supervisor, and this supervisor has a smaller employee ID and a higher rank (the value of rank is smaller); and
  3. Each employee can supervise at most 2 people.

Alice and Bob are eager to know whether their company can be reorganized successfully.

입력

The input is a total of n + 1 lines. The first line contains n (1 ≤ n ≤ 100, 000), indicating the number of employees. On the next n lines are n distinct integers R (1 ≤ R ≤ 10, 000, 000), one integer per line, where the ith integer indicates the rank of the employee with ID i.

출력

Output YES if the company can be reorganized successfully; output NO otherwise.

제한

예제 입력 1

6
1
6
5
2
3
4

예제 출력 1

NO

Employee with rank 1 has employee ID 1, and thus, must be the supervisor. Employees 2 and 3 (with ranks 6 and 5) can only be supervised by employee 1 (with rank 1). However, no other employee (4, 5 or 6) can be supervised by employee 2 or employee 3, since ranks of supervisors must be smaller than the employees they supervise.

예제 입력 2

6
1
6
2
3
4
5

예제 출력 2

YES

Employee 1 (rank 1) supervises both employee 2 (rank 6) and employee 3 (rank 2).

Employee 3 (rank 2) supervises employee 4 (rank 3) and employee 5 (rank 4).

Employee 4 (rank 3) supervises employee 6 (rank 5).

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2011 > CCO 2011 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /