• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #212 Div2 B

B. Petya and Staircases
time limit per test 1 second
memory limit per test 256 megabytes
 

Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.

Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once.

One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.

Input

The first line contains two integers n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≤ di ≤ n) — the numbers of the dirty stairs (in an arbitrary order).

Output

Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO".

Sample test(s)
Input
10 5 
2 4 8 3 6
Output
NO
Input
10 5 
2 4 5 7 9
Output
YES
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 #define maxn 30005
 6 int a[maxn];
 7 int main(){
 8     int t, n, m;
 9     scanf("%d%d",&n,&m);
10     for (int i = 0; i < m; i++){
11         scanf("%d", &a[i]);
12     }
13     sort(a, a + m);
14     int flag = 1;
15     if (a[0] == 1 || a[m - 1] == n){ printf("NO\n"); return 0; }
16     for (int i = 0; i < m-2; i++){
17         if (a[i] + 1 == a[i + 1] && a[i] + 2 == a[i + 2]){ flag = 0; break; }
18     }
19     if (flag){ printf("YES\n"); }
20     else printf("NO\n");
21     return 0;
22 }
View Code
posted @ 2013-11-15 09:45  HaibaraAi  阅读(111)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3