P27131 [AtCoder] Graph Problem
提高+
题目描述

Problem Description

Determine whether there exists an undirected simple graph with $ N $ vertices such that the degree of each vertex is $ D_1, ..., D_N $ respectively. If it does not exist, determine whether it is possible to make such a graph exist by increasing $ D_i $ by 1 for some $ i $.

Input Format

The input is given from the standard input in the following format:

$ N $ $ D_1 $ : $ D_N $

Output Format

If there exists an undirected simple graph with $ N $ vertices such that the degree of each vertex is $ D_1, ..., D_N $ respectively, output YES.

Otherwise, if it is possible to make such a graph exist by increasing $ D_i $ by 1 for some $ i $, output NO.

Otherwise, output ABSOLUTELY NO.

Sample Input and Output

Sample Input #1

5
1
2
2
3
4

Sample Output #1

YES

Sample Input #2

7
1
1
1
1
6
6
6

Sample Output #2

ABSOLUTELY NO

Sample Input #3

8
1
1
1
2
3
4
4
5

Sample Output #3

NO

Notes/Hints

Constraints

  • $1 \leq N \leq 10^5$
  • $0 \leq D_i \leq N-1 (1 \leq i \leq N)$
  • $D_i \leq D_{i+1} (1 \leq i \leq N-1)$
  • All inputs are integers.

Sample Explanation 1

A graph with the edge set $ {(1,5),(2,4),(2,5),(3,4),(3,5),(4,5)} $ satisfies the conditions.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 1 2 2 3 4
样例输出
YES