Guest User

Untitled

a guest
May 24th, 2019
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. ///vector is an array with size of k, don't be afraid
  5. int main() {
  6. int n, k;
  7. cin >> n >> k;
  8. vector<int> a1 (k); //nums of left bus st
  9. vector<int> a2 (k); //nums of right bus st
  10. for (int i = 0; i < k; i++)
  11. cin >> a1[i] >> a2[i];
  12. int left = a1[0], right = a2[0];
  13. for (int w = 0; w < 2; w++) // double cycle
  14. for (int i = 1; i < k; i++)
  15. if ((a1[i] >= left && a1[i] <= right)||(a2[i] >= left && a2[i] <= right))
  16. {
  17. right = max(right, a2[i]);
  18. left = min(left, a1[i]);
  19. }
  20. if (left == 1 && right == n) cout << "YES";
  21. else cout << "NO";
  22. return 0;
  23. }
RAW Paste Data