int main()
{
int n;
cin>>n;
int idx=0;
vector <pair <int,int>> a;
for (int j=0; j<n; j++)
{
int x,y;
cin>>x>>y;
a.push_back({x,y});
}
sort(a.begin(),a.end());
for(int i=1;i<n;i++)
{
int start1= a[idx].first;
int end1=a[idx].second;
int start2=a[i].first;
int end2=a[i].second;
if (end1>=start2)
{
//then merge
end1=max(end1,end2);
start1=min(start1,start2);
}
else if (end1<start2)
{
idx++;
start1=start2;
end1=end2;
}}
for (int k=0;k<idx;k++)
{
cout<<a[k].first<<" "<<a[k].second;
cout<<endl;
}
}
This is my code I have written but I am getting wrong answer...
I gave the no of pairs (n) = 3 as input and entered the values [1,3][2,5][6,7] so answer must be [1,5][6,7] but I am getting [1,3]...I don't know why so please help me THANK YOU