845C. Two TVs - Codeforces Solution C++

  Problem Link : 845C. Two TVs 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

int main()
{
	int n;
	ll l,r;
	cin>>n;
	vector<pair<ll,ll> > v;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		v.push_back(make_pair(l,r));
	}

	sort(v.begin(),v.end());

	l=-1,r=-1;

	bool flag=1;

	for(int i=0;i<v.size();i++)
	{
		if(v[i].first > l)
			l = v[i].second;
		else if(v[i].first > r)
			r = v[i].second;
		else
		{
			flag=0;
			break;
		}
	}
	if(flag)
		cout<<"YES";
	else
		cout<<"NO";
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!