CF429C.Guess the Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food.

Iahub asks Iahubina: can you build a rooted tree, such that

  • each internal node (a node with at least one son) has at least two sons;
  • node ii has cic_{i} nodes in its subtree?

Iahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain nn nodes.

输入格式

The first line of the input contains integer nn ( 1<=n<=241<=n<=24 ). Next line contains nn positive integers: the ii -th number represents cic_{i} (1<=ci<=n)(1<=c_{i}<=n) .

输出格式

Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).

输入输出样例

  • 输入#1

    4
    1 1 1 4
    

    输出#1

    YES
  • 输入#2

    5
    1 1 5 2 1
    

    输出#2

    NO
首页