Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream f("acoperire.in");
- ofstream g("acoperire.out");
- pair<int,int> a[1005];
- int x,y,n,i,sol,start,finish;
- int main()
- {
- f>>x>>y;
- f>>n;
- for(i=1;i<=n;i++)
- {
- f>>a[i].first>>a[i].second;
- }
- a[n+1].first=10005;
- a[n+1].second=10005;
- n=n+1;
- sort(a+1,a+n+1);
- start=x;
- finish=x-1;
- i=1;
- while(i<=n)
- {
- //cout<<a[i].first<<" ";
- if(a[i].first<=start)
- {
- finish=max(finish,a[i].second);
- i++;
- }
- else
- {
- start=finish;
- //cout<<i-1<<" ";
- sol++;
- if(a[i].first>finish || finish>=y)
- {
- break;
- }
- }
- }
- //cout<<finish<<" ";
- if(finish<y)
- {
- g<<-1;
- }
- else
- {
- g<<sol;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement