First 2 test cases didnt pass

Hey @bhadra28 that might be because you are sorting it without any comparator , see this and implement it in your code. Your logic is correct.

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool compare(pair<int,int>p1,pair<int,int>p2){
    if(p1.second == p2.second) return p1.first<p2.first;
	return p1.second<p2.second;
}
int main(){
	int n;
    cin>>n;
    int y,r;
	vector<pair<int,int> >v;
    for(int i=0;i<n;i++){
        cin>>y>>r;
		int s,e;
		s=y-r;
		e=y+r;
		v.push_back(make_pair(s,e));
	
    } 
	sort(v.begin(),v.end(),compare);
	int ans=0;
    int curr = v[0].second;
	for(int i=1;i<n;i++){
		if(v[i].first>=curr){
			curr = v[i].second;
		}
        else{
            ans++;
        }
	}
	cout<<ans<<endl;
    return 0;
}

yeah got it. thanks…

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.