CF128D.Numbers
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her younger sister Maria came and shuffled all numbers. Anna got sick with anger but what's done is done and the results of her work had been destroyed. But please tell Anna: could she have hypothetically completed the task using all those given numbers?
一天,安娜在学校收到了如下任务:将若干个数字排成一个圆圈,使得任意两个相邻的数字之差的绝对值恰好为 1。安娜拿到了若干个数字,并将它们排成了一个圆圈以完成该任务。随后她想检查自己是否正确地完成了排列,但此时她的妹妹玛丽亚跑了过来,把所有数字都打乱了。安娜气得生病了,但事已至此,她之前的工作成果已被彻底破坏。不过,请你告诉安娜:她是否有可能(仅从理论上讲)用所有这些给定的数字完成该任务?
输入格式
The first line contains an integer n — how many numbers Anna had (3 ≤ n ≤ 105). The next line contains those numbers, separated by a space. All numbers are integers and belong to the range from 1 to 109.
第一行包含一个整数 n —— 表示安娜拥有的数字个数(3≤n≤105)。下一行包含这些数字,以空格分隔。所有数字均为整数,且取值范围为 1 到 109。
输出格式
Print the single line "YES" (without the quotes), if Anna could have completed the task correctly using all those numbers (using all of them is necessary). If Anna couldn't have fulfilled the task, no matter how hard she would try, print "NO" (without the quotes).
如果安娜能够正确地使用所有这些数字(必须全部使用)完成任务,则输出单行“YES”(不带引号);如果无论安娜如何努力都无法完成任务,则输出“NO”(不带引号)。
输入输出样例
输入#1
4 1 2 3 2
输出#1
YES
输入#2
6 1 1 2 2 2 3
输出#2
YES
输入#3
6 2 4 1 1 2 2
输出#3
NO
输入解题思路,AI测评打分。不知道怎么写?