Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. using namespace std;
  5. ifstream f("acoperire.in");
  6. ofstream g("acoperire.out");
  7. pair<int,int> a[1005];
  8. int x,y,n,i,sol,start,finish;
  9. int main()
  10. {
  11. f>>x>>y;
  12. f>>n;
  13. for(i=1;i<=n;i++)
  14. {
  15. f>>a[i].first>>a[i].second;
  16. }
  17. a[n+1].first=10005;
  18. a[n+1].second=10005;
  19. n=n+1;
  20. sort(a+1,a+n+1);
  21. start=x;
  22. finish=x-1;
  23. i=1;
  24. while(i<=n)
  25. {
  26. //cout<<a[i].first<<" ";
  27. if(a[i].first<=start)
  28. {
  29. finish=max(finish,a[i].second);
  30. i++;
  31. }
  32. else
  33. {
  34. start=finish;
  35. //cout<<i-1<<" ";
  36. sol++;
  37. if(a[i].first>finish || finish>=y)
  38. {
  39. break;
  40. }
  41. }
  42. }
  43. //cout<<finish<<" ";
  44. if(finish<y)
  45. {
  46. g<<-1;
  47. }
  48. else
  49. {
  50. g<<sol;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement