Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N=2e5+10;
- struct Interval
- {
- int l, r;
- friend bool operator<(const Interval& p, const Interval& q)
- {
- if (p.r==q.r) return p.l>q.l;
- return p.r<q.r;
- }
- } seg[N];
- int n;
- int schedule ()
- {
- int ret=1, idx=0;
- sort (seg, seg+n);
- for (int i=1;i<n;i++)
- {
- if (seg[i].l>=seg[idx].r)
- {
- idx=i;
- ret++;
- }
- }
- return ret;
- }
- int main()
- {
- scanf ("%d", &n);
- for (int i=0;i<n;i++)
- {
- int x, w;
- scanf ("%d%d", &x, &w);
- seg[i].l=x-w;
- seg[i].r=x+w;
- }
- printf ("%d", schedule());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment