Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- ///vector is an array with size of k, don't be afraid
- int main() {
- int n, k;
- cin >> n >> k;
- vector<int> a1 (k); //nums of left bus st
- vector<int> a2 (k); //nums of right bus st
- for (int i = 0; i < k; i++)
- cin >> a1[i] >> a2[i];
- int left = a1[0], right = a2[0];
- for (int w = 0; w < 2; w++) // double cycle
- for (int i = 1; i < k; i++)
- if ((a1[i] >= left && a1[i] <= right)||(a2[i] >= left && a2[i] <= right))
- {
- right = max(right, a2[i]);
- left = min(left, a1[i]);
- }
- if (left == 1 && right == n) cout << "YES";
- else cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement