Josif_tepe

Untitled

Dec 23rd, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. #include <set>
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.    
  11.     pair<int, int> a[n];
  12.    
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> a[i].second >> a[i].first;
  15.     }
  16.    
  17.     sort(a, a + n);
  18.    
  19.     int zemen = a[0].first;
  20.     // .first --> krajot na filmot
  21.     // .second --> pocetok na filmot
  22.    
  23.     int res = 1;
  24.     for(int i = 1; i < n; i++) {
  25.         if(zemen <= a[i].second) {
  26.             res++;
  27.             zemen = a[i].first;
  28.         }
  29.     }
  30.    
  31.     cout << res << endl;
  32.  
  33.     return 0;
  34. }
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment