题目链接:

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后端技术

    技术概论:Springmvc+mybatis+shiro+Dubbo+ZooKeeper+Redis+KafKa j2ee分布式架构 我在恒生工作,主要开发金融互联网第三方平台的对接项目.目前已经对接 ...

  2. 几种session存储方式比较

    原文: http://blog.sina.com.cn/s/blog_495697e6010143tj.html 集群中session安全和同步是个最大的问题,下面是我收集到的几种session同步的 ...

  3. VirtualBox + CentOS 虚拟机网卡配置

    摘要: 要学好Linux,还是得自己搭建虚拟机. VirtualBox比较小巧简单,容易上手.在配合CentOS 6.4使用时,首要的问题就是网卡配置,尤其是使用SSH终端仿真程序(例如SecureC ...

  4. Laravel开发:Laravel框架门面Facade源码分析

    前言 这篇文章我们开始讲 laravel 框架中的门面 Facade,什么是门面呢?官方文档: Facades(读音:/fəˈsäd/ )为应用程序的服务容器中可用的类提供了一个「静态」接口.Lara ...

  5. windows下php配置redis

    方法/步骤 1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本   2.根据PHP版本号,编译器版本号和CPU架构, 选择php_redis-2.2.5-5.5-ts-vc11- ...

  6. 九度OJ 1183:守形数 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3815 解决:2005 题目描述: 守形数是这样一种整数,它的平方的低位部分等于它本身. 比如25的平方是625,低位部分是25,因此25是 ...

  7. information entropy as a measure of the uncertainty in a message while essentially inventing the field of information theory

    https://en.wikipedia.org/wiki/Claude_Shannon In 1948, the promised memorandum appeared as "A Ma ...

  8. 算法设计 mac 字符串 标识 n维度 2 3维度 字符串 标识值 特征值

    基向量

  9. [POI2006]SZK-Schools

    [POI2006]SZK-Schools luogu #include<bits/stdc++.h> using namespace std; const int N=405,M=1e5+ ...

  10. PAT 1052. 卖个萌 (20)

    萌萌哒表情符号通常由“手”.“眼”.“口”三个主要部分组成.简单起见,我们假设一个表情符号是按下列格式输出的: [左手]([左眼][口][右眼])[右手] 现给出可选用的符号集合,请你按用户的要求输出 ...