#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 5e4 + 10;
struct node{
int l, r;
bool operator < (const node &a) const {
return l < a.l;
}
}a[MAXN]; // 查找第一个大于v的值
int binary_search(int l, int r, int v){
int m;
while(l < r){
m = (l + r)>>1;
if(a[m].l <= v) l = m + 1;
else r = m;
}
return l;
}
int main(){
int n, p, r;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d%d", &p, &r);
a[i].l = p - r;
a[i].r = p + r;
}
sort(a, a + n);
int ans = 0, index;
for(int i = 0; i < n - 1; ++i){
index = binary_search(i, n, a[i].r);
ans += n - index;
}
printf("%d\n", ans);
return 0;
}
1278 相离的圆
最新推荐文章于 2018-07-27 08:45:44 发布