In test case 3 getting wrong ans

#include
#include
using namespace std;

struct circle {
int start, end;
};

// Comparison function modified
// according to the end value
bool comp(circle a, circle b)
{
if (a.end == b.end)
return a.start < b.start;
return a.end < b.end;
}

// Function to return the count
// of non intersecting circles
void CountCircles(int c[], int r[], int n)
{
// structure with start and
// end of diameter of circles
circle diameter[n];

for (int i = 0; i < n; ++i) { 
    diameter[i].start = c[i] - r[i]; 

    diameter[i].end = c[i] + r[i]; 
} 

// sorting with smallest finish time first 
sort(diameter, diameter + n, comp); 

// count stores number of 
// circles to be removed 
int count = 0; 

// cur stores ending of first circle 
int cur = diameter[0].end; 
for (int i = 1; i < n; ++i) { 

    // non intersecting circles 
    if (diameter[i].start > cur) { 
        cur = diameter[i].end; 
    } 

    // intersecting circles 
    else
        count++; 
} 

cout << count << "\n"; 

}

// Driver Code
int main()
{
int n;
cin>>n;
int c[n];
int r[n];
for(int i=0;i<n;i++){
cin>>c[i];
cin>>r[i];
}

CountCircles(c, r, n); 

return 0; 

}

Hey @mansi25 please share your code using ide.codingblocks.com .

check now ->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.