Advertisement
Josif_tepe

Untitled

Jul 13th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.   int n;
  7.   cin >> n;
  8.  
  9.   pair<int, int> brod[n];
  10.  
  11.  
  12.     for (int i = 0; i < n; i++)
  13.     {
  14.         cin >> brod[i].second >> brod[i].first;
  15.     }
  16.  
  17.  
  18.     sort(brod,brod + n);
  19.  
  20.  
  21.     int L = brod[0].first - brod[0].second;
  22.     int R = brod[0].first;
  23.   int  res = 1;
  24.  
  25.  
  26.     for(int i = 1; i < n;i++) {
  27.  
  28.         int l = brod[i].second;
  29.         int p = brod[i].first;
  30.  
  31.         if (p >= R) {
  32.           L = max(p - l, R);
  33.           R = L + l;
  34.           res++;
  35.         }
  36.         else {
  37.           int x = max(p, L + l);
  38.           if (x < R) {
  39.             R = x;
  40.           }
  41.         }
  42.  
  43.     }
  44. cout << res << endl;
  45.   return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement