#P15400. [NOISG 2026 Prelim] Hungry Cats

    ID: 18373 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟贪心排序2026NOISG(新加坡)

[NOISG 2026 Prelim] Hungry Cats

Problem Description

In the kingdom of cannibalistic cats, Ket the cat has just been informed that National Cat Day (NCD) will be held tomorrow. As the appointed software engineer, he is tasked with developing a system to report on the cannibalism situation.

There are nn cats joining the NCD celebration, numbered from 1 to nn. The ii-th cat has a happiness level of h[i]h[i]. At any point in time, a cat may eat a strictly less happy cat. After this happens, the happier cat’s happiness level increases by 11 and it is no longer able to eat any other cats. In addition, the less happy cat vanishes.

Ket is tasked with determining whether it is possible for only one cat to be left at the end of the celebration. This means that all other cats were eaten.

Input Format

Your program must read from standard input.

The first line of input contains an integer nn.

The second line of input contains nn space-separated integers h[1],h[2],,h[n]h[1], h[2], \ldots, h[n].

Output Format

Your program must print to standard output.

Output YES if it is possible for only one cat to be left after the celebration, or NO otherwise.

2
3141 59
YES
3
31 41 59
YES
5
10 0 24 25 10
NO
6
2 25 11 5 20 26
NO

Hint

Sample Test Case 2 Explanation

There are n=3n = 3 cats with hunger levels 3131, 4141, and 5959. It is possible for one cat to be left after the celebration if the second cat eats the first cat and subsequently gets eaten by the third cat.

Sample Test Case 3 Explanation

It is impossible for the cats to eat each other in a way that leaves one cat remaining at the end of the celebration.

Subtasks

For all test cases, the input will satisfy the following bounds:

  • 2n2000002 \le n \le 200\,000
  • 0h[i]1090 \le h[i] \le 10^9 for all 1in1 \le i \le n

Your program will be tested on input instances that satisfy the following restrictions:

Subtask Score Additional Constraints
0 Sample test cases
1 8 n=2n = 2
2 10 n3n \le 3
3 6 h[1]=h[n]h[1] = h[n]
4 18 n1000n \le 1000
5 28 hh is non-decreasing (h[i]h[i+1]h[i] \le h[i+1] for all 1in11 \le i \le n-1)
6 30 No additional constraints