-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path1134. Cards.cpp
60 lines (50 loc) · 1017 Bytes
/
1134. Cards.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int const N = 1e4 + 1;
int n, m, a[N], fr[N];
int main() {
scanf("%d %d", &n, &m);
if(m > n) {
puts("NO");
return 0;
}
for(int i = 0; i < m; ++i)
scanf("%d", a + i);
sort(a, a + m);
fr[0] = fr[n] = 1;
for(int i = 1; i <= n - 1; ++i)
fr[i] = 2;
for(int i = 0; i < m; ++i) {
if(a[i] == 0) {
if(fr[0] <= 0 || fr[1] <= 0) {
puts("NO");
return 0;
} else {
--fr[0], --fr[1];
continue;
}
}
if(a[i] == n) {
if(fr[n] <= 0 || fr[n - 1] <= 0) {
puts("NO");
return 0;
} else {
--fr[n], --fr[n - 1];
continue;
}
}
if(fr[a[i]] > 0 && (fr[a[i] + 1] > 0 || fr[a[i] - 1] > 0)) {
--fr[a[i]];
if(fr[a[i] - 1] > 0)
--fr[a[i] - 1];
else if(fr[a[i] + 1] > 0)
--fr[a[i] + 1];
} else {
puts("NO");
return 0;
}
}
puts("YES");
return 0;
}