Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <bits/stdc++.h>using namespace std;int main(){int n, x, y;cin >> n >> x >> y;vector<pair<int, int>> invals;for(int i = 0; i < n; i++){int l, r;cin >> l >> r;invals.push_back(make_pair(l, r));}sort(invals.begin(), invals.end());int ans = 0, i = 0, last = INT_MIN;while(i < n && x > 0 && x < y){//cout << x << endl;if(invals[i].first <= x){if(invals[i].second >= x) last = max(last, invals[i].second);i++;}else{x = last+1;ans++;}}if(i == n) ans++;if(last < y) cout << -1 << endl;else cout << ans << endl;}