In this question, I have applied the greedy approach but getting the wrong answer. I have sorted all the pair according to order that the circle whose the second intersection with the x-axis is minimum will come first.
#include<bits/stdc++.h>
using namespace std;
bool cmp(pair<long long int,long long int>c,pair<long long int,long long int>d)
{
return c.second<d.second;
}
int main()
{
long long int n;
cin>>n;
long long int a[n],b[n],i,k,l,s=0;
pair<long long int,long long int>c[n];
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
c[i].first=a[i]-b[i];
c[i].second=a[i]+b[i];
}
sort(c,c+n,cmp);
s++;
k=c[0].second;
for(i=1;i<n;i++)
{
l=c[i].first;
if(l>=k)
{
k=c[i].second;
s++;
}
}
cout<<s<<endl;
}