src2020/4095_xmly/main.cpp

48 lines
820 B
C++

#include<iostream>
#include <algorithm>
using namespace std;
int n;
bool ce[100001]={0};
struct link{
int x,y;
}a[100001];
bool pan(link yi,link er){
return yi.x<er.x;
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y;
}
sort(a,a+n,pan);
/*
for (int i = 0; i <n; i++) {
cout<<a[i].x<<" "<<a[i].y <<endl;
}*/
int now=0,ans=n;
for(int i=1;i<n;i++){
if(a[now].y+a[now].x-a[i].x>=a[i].y){
ce[i]=1;
//cout<<ans<<" "<<a[i].x<<" "<<a[i].y <<endl;
}else{
now=i;
}
}
now=n-1;
if(ce[now]==1){
ans--;
}
for(int i=n-2;i>=0;i--){
if(a[now].y-(a[now].x-a[i].x)>=a[i].y){
ce[i]=1;
//cout<<ans<<" "<<a[i].x<<" "<<a[i].y <<endl;
}else{
now=i;
}
if(ce[i]==1){
ans--;
}
}
cout<<ans;
}