Advertisement
Dennnhhhickk

Untitled

Jan 29th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n, m;
  10. cin >> n >> m;
  11. vector <int> a(m);
  12. bool bol[n + 1][n + 1];
  13. bool ans = 1;
  14. for (int i = 0; i < m; i++)
  15. cin >> a[i];
  16. sort(a.begin(), a.end());
  17. for (int i = 0; i <= n; i++)
  18. for (int j = 0; j <= n; j++)
  19. bol[i][j] = 0;
  20. //_____________________________________
  21. for (int i = 0; i < m; i++){
  22. if (a[i] - 1 >= 0 && !bol[a[i]][a[i] - 1]){
  23. bol[a[i]][a[i] - 1] = 1;
  24. bol[a[i] - 1][a[i]] = 1;
  25. }
  26. else
  27. if (a[i] + 1 <= n && !bol[a[i]][a[i] + 1]){
  28. bol[a[i]][a[i] + 1] = 1;
  29. bol[a[i] + 1][a[i]] = 1;
  30. }
  31. else{
  32. ans = 0;
  33. break;
  34. }
  35. }
  36. //_____________________________________
  37. if (ans)
  38. cout << "YES";
  39. else
  40. cout << "NO";
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement