坐标轴上有n个点,每个点有一个权值。第i个点的坐标是 xi ,权值是 wi 。现在对这些点建图。对于点对 (i,j) ,如果 |xi−xj|≥wi+wj ,那么就给第i个点和第j个点之间连一条边。
问建好的图中最大团有几个点。
样例解释:
![](https://img.51nod.com/upload/000FBF42/08D2CB7451B68EFD0000000000000017.png)
Input
单组测试数据。 第一行有一个整数n (1≤n≤200000),表示坐标轴上有n个点。 接下来n行,每一行有两个整数xi, wi (0≤xi≤10^9,1≤wi≤10^9),表示第i个点的坐标和权值。 所有的xi是不一样的。
Output
输出一个整数,表示最大团中有几个点。
Input示例
样例输入1 4 2 3 3 1 6 1 0 2
Output示例
样例输出1 3
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <limits.h>
using namespace std;
const int MAXN = 2e5 + 10;
struct node
{
int l, r;
};
int n;
node a[MAXN];
inline int _read()
{
int num = 0;
char ch = getchar();
while (ch < '0' || ch > '9')
{
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
num = num * 10 + ch - 48;
ch=getchar();
}
return num;
}
bool cmp(node a, node b)
{
if (a.r == b.r)
{
return a.l < b.l;
}
return a.r < b.r;
}
int main()
{
cin >> n;
int x, w;
for (int i = 0; i < n; i++)
{
x = _read();
w = _read();
a[i].l = x - w;
a[i].r = x + w;
}
sort(a, a + n, cmp);
int L = INT_MIN;
int result = 0;
for (int i = 0; i < n; i++)
{
if (a[i].l >= L)
{
L = a[i].r;
result++;
}
}
printf("%d\n", result);
return 0;
}