题目链接:

A. Bear and Three Balls

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Limak is a little polar bear. He has n balls, the i-th ball has size ti.

Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:

  • No two friends can get balls of the same size.
  • No two friends can get balls of sizes that differ by more than 2.

For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).

Your task is to check whether Limak can choose three balls that satisfy conditions above.

Input

The first line of the input contains one integer n (3 ≤ n ≤ 50) — the number of balls Limak has.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 1000) where ti denotes the size of the i-th ball.

Output

Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).

Examples
input
4
18 55 16 17
output
YES
input
6
40 41 43 44 44 44
output
NO
input
8
5 972 3 4 1 4 970 971
output
YES
Note

In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes18, 16 and 17.

In the second sample, there is no way to give gifts to three friends without breaking the rules.

In the third sample, there is even more than one way to choose balls:

  1. Choose balls with sizes 3, 4 and 5.
  2. Choose balls with sizes 972, 970, 971.

题意:就是问你是否有连续的三个数;

AC代码:

#include <bits/stdc++.h>
using namespace std;
int a[],num[];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
num[a[i]]++;
}
for(int i=;i<=;i++)
{
if(num[i]&&num[i+]&&num[i+])
{
cout<<"YES";
return ;
}
}
cout<<"NO";
return ;
}

codeforces 653A A. Bear and Three Balls(水题)的更多相关文章

  1. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题

    A. Bear and Three Balls 题目连接: http://www.codeforces.com/contest/653/problem/A Description Limak is a ...

  2. codeforces 680B B. Bear and Finding Criminals(水题)

    题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...

  3. codeforces 680A A. Bear and Five Cards(水题)

    题目链接: A. Bear and Five Cards //#include <bits/stdc++.h> #include <vector> #include <i ...

  4. codeforces 658A A. Bear and Reverse Radewoosh(水题)

    题目链接: A. Bear and Reverse Radewoosh time limit per test 2 seconds memory limit per test 256 megabyte ...

  5. CodeForces 653 A. Bear and Three Balls——(IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2))

    传送门 A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  7. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  8. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  9. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

随机推荐

  1. java实体类如果不重写toString方法,会如何?

    先认识一下Object Object 类的 toString 方法 返回一个字符串,该字符串由类名(对象是该类的一个实例).at 标记符“@”和此对象哈希码的无符号十六进制表示组成.换句话说,该方法返 ...

  2. python基础: day4作业计算器

    作业:计算器开发 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - ...

  3. Linux 随手记(文件操作)

    新建文件夹 mkdir 文件夹名 新建文件 touch 文件名 重命名 mv 文件名 新文件名 将/a目录移动到/b下,并重命名为c mv /a /b/c 复制文件 cp [选项] 源文件或目录 目标 ...

  4. maven;cargo;仓库

    [说明]又到晚上九点了,不得不加快进度,首先就是日报.今天上午在服务器搭建maven,下午完成了一个maven web项目,晚上改错找maven配置问题(因为想装jetty和cargo) 一:今日完成 ...

  5. 海康,睿网设备SDK调试

    引入 外部dll  DllImport [DllImport(@"../bin/HCNetSDK.dll")] 问题1: 找不到模块.... 解决:  [DllImport(@&q ...

  6. [BJWC2012]冻结

    [BJWC2012]冻结 luogu BZOJ 分层图最短路,层与层之间连半边权边 #include<bits/stdc++.h> using namespace std; const i ...

  7. ros下单目相机校正

    1. 安装对应的驱动与程序包. 图像对应包   http://wiki.ros.org/camera_calibration          在gitbub下载image_pipeline :    ...

  8. bug-3——onload,onbeforeunload,Onunload的区别

    window.onload事件设置页面加载时执行的动作,即进入页面的时候执行的动作.   window.onunload已经从服务器上读到了需要加载的新的页面,在即将替换掉当前页面时调用 一般用于设置 ...

  9. ABAP面试经历【转http://blog.csdn.net/tsj19881202/article/details/8792742】

    本周三面试了一次HP的globe部门,整个过程自己感觉特别糟糕.总结了一下经验, 1.不能把自己平时做的东西,很好的用语言描述出来 2.技术点其实都会,但是不了解对方问题的意思,所以没能很好的回答对方 ...

  10. SAP后台作业记录操作

    [转http://blog.163.com/liang_ce_521@126/blog/static/709202152013073376596/]后台作业信息存储在透明表TBTCP(批作业步骤概述) ...