题目描述
小蓝有 n 种糖果,每种数量已知。
小蓝不喜欢连续 2 次吃同样的糖果。问有没有可行的吃糖方案。
输入描述
第一行是整数 n(0<n<1000000)。
第二行包含 n 个数,表示 n 种糖果的数量
输出描述
输出一行,包含一个 Yes 或 no。
输入输出样例
示例
输入
3
4 1 1
输出
No
运行限制
最大运行时间:1s
最大运行内存: 256M
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
//统计所有糖果数量
long sum=0;
//统计最多糖果数量是多少
int max= 0;
for (int i = 0; i < n; i++) {
int x=sc.nextInt();
sum+=x;
max=Math.max(max,x);
}
if (max-(sum-max)>1){
System.out.println("No");
}else {
System.out.println("Yes");
}
}
}