Maximum Circles Problem

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;
}

This problem is just like activity selection problem. Starting point of circle is c-r and ending point is c+r so you can select them accordingly.

Yes i understood that. I tried implementing accordingly, but yet two test cases failed. It’d be really helpful if you could go through my code once, and tell what am i doing wrong.

@anuragdeol2017 you are pushing c and r, you should consider c-r and c+r as starting and ending point and apply the logic on that.