Giving Tle .. in maximum circle

code- https://ide.codingblocks.com/s/319005

my code giving TLE
how to solve this .

what other better approach i can use

can any one help with this

Rishav, the approach you are using in your code is wrong…Try using this approach as :

class Circle
{
public:
long long int radius;
long long int centre;
};
bool myCompare(Circle a,Circle b)
{
return (a.centre+a.radius)<(b.centre+b.radius);
}
int main()
{
long long int n;
cin>>n;
Circle ar[n];
for(int i=0;i<n;i++)
{
cin>>ar[i].centre>>ar[i].radius;
}
sort(ar,ar+n,myCompare);
int c=1;
int end=ar[0].centre+ar[0].radius;
for(int i=1;i<n;i++)
{
int start=ar[i].centre-ar[i].radius;
if(end<=start)
{
c++;
end=ar[i].centre+ar[i].radius;
}
}
// c is no of circles that need not to be removed
cout<<(n-c);
return 0;
}