2 out of 6 test cases are failing. Please help.
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long int
using namespace std;
int f(vector<pair<ll,ll>> v, int n){
sort(v.begin(), v.end());
int cnt = 0;
for(int i=0,j=1; i<n and j<n; ){
if(v[j].first-v[j].second < v[i].first+v[i].second){
cnt++;
j++;
}
else{
i=j;
j++;
}
}
return cnt;
}
int main(){
int n;
cin>>n;
vector<pair<ll,ll>> v;
for(int i=0; i<n; i++){
ll c,r;
cin>>c>>r;
v.push_back(make_pair(c,r));
}
cout<<f(v,n);
return 0;
}