#include <bits/stdc++.h>
using namespace std;
struct st {
int l;//左边山脚的X坐标
int r;//右边山脚的X坐标
};
struct st a[100005];
//按左边山脚坐标排序,
//相同的右边山脚靠右的往前排
//保证不会出现后边遮蔽前边
bool cmp(struct st s1, struct st s2) {
if (s1.l == s2.l) return s1.r >= s2.r;
else return s1.l < s2.l;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x,y;
scanf("%d %d", &x, &y);
a[i].l = x - y;//计算左边山脚
a[i].r = x + y;//计算右边山脚
}
sort(a + 1, a + n + 1, cmp);//排序
int mx=0;//最大覆盖范围
int ans=0;
for (int i = 1; i <= n; i++) {
if (a[i].r>mx){//未被覆盖
ans++;
mx=a[i].r;//修改最大覆盖范围
}
}
cout << ans << endl;
return 0;
}
评论区