Maximum circles problem

sample test case clear but on submission
code fail to clear test cases
why ?
please help me to figure out

please check where you are going wrong…

#include<bits/stdc++.h>
using namespace std;
bool cmp(pair<int,int> a,pair<int,int> b)
{
    return(b.second>a.second);
}
int main() 
{
    int ans = 1;
    int n,c,r;
    cin>>n;
    vector< pair<int,int> > v;
    for(int i=0;i<n;i++)
    {
        cin>>c>>r;
        v.push_back(make_pair(c-r,r+c));
    }
    sort(v.begin(),v.end(),cmp);
    int val=v[0].second;
    for(int i=1;i<n;i++)
    {
        if(val<=v[i].first)
        {
            ans++;
            val=v[i].second;
        }
    }

    cout<<n-ans;
}

why
cout<<n-ans<<endl;
why not
cout<<ans<<endl;

because we need minimum number of circles that to be removed.

1 Like

oh yeah got it.
i was counting maximum number of circle without overlapping.
thank you very much.