Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- pair<int, int> brod[n];
- for (int i = 0; i < n; i++)
- {
- cin >> brod[i].second >> brod[i].first;
- }
- sort(brod,brod + n);
- int L = brod[0].first - brod[0].second;
- int R = brod[0].first;
- int res = 1;
- for(int i = 1; i < n;i++) {
- int l = brod[i].second;
- int p = brod[i].first;
- if (p >= R) {
- L = max(p - l, R);
- R = L + l;
- res++;
- }
- else {
- int x = max(p, L + l);
- if (x < R) {
- R = x;
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement