2 test cases are getting wrong answer
PLease check my code
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
bool compare(pair<ll,ll>p1,pair<ll,ll>p2){
if(p1.first!=p2.first){
return p1.first<p2.first;
}else{
return p1.second < p2.second;
}
}
int main() {
ll n;
cin>>n;
vector<pair<ll,ll>>v;
ll ans = 0;
ll curr_sum=0;
for(int i=0;i<n;i++){
ll x,y;
cin>>x>>y;
v.push_back(make_pair(x,y));
}
sort(v.begin(),v.end(),compare);
ll last = (v[0].first+v[0].second);
ll count = 0;
for(ll i=1;i<n;i++){
pair<ll,ll>p;
p = v[i];
ll curr = p.first - p.second;
if(curr<last){
count++;
last = min(curr+2p.second,last);
}else{
last = curr+ 2p.second;
}
}
cout << count << endl;
}
Here first we have sorted the circles by their center.Then if they are overlapping then we have removed the circle with bigger value of (c+r),This ensures that we will remove min circle to make circle non overlapping
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.