Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- vector <int> a(m);
- bool bol[n + 1][n + 1];
- bool ans = 1;
- for (int i = 0; i < m; i++)
- cin >> a[i];
- sort(a.begin(), a.end());
- for (int i = 0; i <= n; i++)
- for (int j = 0; j <= n; j++)
- bol[i][j] = 0;
- //_____________________________________
- for (int i = 0; i < m; i++){
- if (a[i] - 1 >= 0 && !bol[a[i]][a[i] - 1]){
- bol[a[i]][a[i] - 1] = 1;
- bol[a[i] - 1][a[i]] = 1;
- }
- else
- if (a[i] + 1 <= n && !bol[a[i]][a[i] + 1]){
- bol[a[i]][a[i] + 1] = 1;
- bol[a[i] + 1][a[i]] = 1;
- }
- else{
- ans = 0;
- break;
- }
- }
- //_____________________________________
- if (ans)
- cout << "YES";
- else
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement