Codeforces Round #212 (Div. 2) B. Petya and Staircases
2016-03-04 23:16
681 查看
B. Petya and Staircases
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 numbern 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 andm (1 ≤ n ≤ 109,0 ≤ m ≤ 3000)
— the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line containsm
different space-separated integersd1, d2, ..., dm (1 ≤ di ≤ n)
— the numbers of the dirty stairs (in an arbitrary order).
Output
Print "YES" if Petya can reach stair numbern, stepping only on the clean stairs. Otherwise print "NO".
Examples
Input
Output
Input
Output
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 numbern 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 andm (1 ≤ n ≤ 109,0 ≤ m ≤ 3000)
— the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line containsm
different space-separated integersd1, d2, ..., dm (1 ≤ di ≤ n)
— the numbers of the dirty stairs (in an arbitrary order).
Output
Print "YES" if Petya can reach stair numbern, stepping only on the clean stairs. Otherwise print "NO".
Examples
Input
10 5 2 4 8 3 6
Output
NO
Input
10 5 2 4 5 7 9
Output
YES
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; int main() { int n,i,m,a[3005]; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); for(i=0;i<m;i++) cin >> a[i]; sort(a,a+m); for(i=2;i<m;i++) { if(a[i]-a[i-1]==1&&a[i-1]-a[i-2]==1) { printf("NO\n"); return 0; } } if(a[0]!=1&&a[m-1]!=n) printf("YES\n"); else printf("NO\n"); return 0; }
相关文章推荐
- 【POJ】[1363]Rails
- vector::clear()和vecotr::pop_back()对内存处理的不同 http://blog.csdn.net/vieri_ch/article/details/1191390
- 【杭电】[1022]Train Problem I
- Leetcode 172 Factorial Trailing Zeroes
- 自定义View时,用到Paint Canvas的一些温故,自定义Loading控件(“六边形”的旋转跳跃)
- lightoj 1282 - Leading and Trailing 【数学】
- 机器学习之初生牛犊
- 【GDKOI2016】项链Code&Details
- [软件测试_hw2]Failure&Error
- How To Reclaim Wasted Space on The Segment (Table, Index and LOB) and Tablespace Levels (文档 ID 16827
- 应用实例:照片识别 机器学习基础(10)
- traincascade相关结构体
- 认知计算是2万亿美元的盛宴,IBM喊你到碗里来!
- 【GDKOI2016】染色大战 Code&Details
- mailto用法
- 【GDKOI2016】寻宝Code&Details
- 【GDKOI2016】不稳定的传送门Code&Details
- LeetCode219题:Contains Duplicate II
- 【GDKOI2016】魔卡少女Code&&Details
- http://blog.csdn.net/luxiaoyu_sdc/article/details/7333024