Advertisement
Josif_tepe

Untitled

Sep 25th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n;
  9. int brojac=1;
  10. cin>>n;
  11. vector<pair<int, int>>v;
  12. for(int i=0; i<n; i++){
  13. int a;
  14. int b;
  15. cin>>a>>b;
  16. v.push_back(make_pair(b, a));
  17. }
  18. sort(v.begin(), v.end());
  19.  
  20.     int nd=v[0].first;
  21.     int start=v[0].second;
  22.  
  23. for(int j=1; j<n; j++){
  24.   int tnd=v[j].first;
  25.   int tstart=v[j].second;
  26.     if(tstart>=nd){
  27.      brojac+=1;
  28.      nd=tnd;
  29.      start=tstart;
  30.     }
  31. }
  32. cout<<brojac;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement