View Code of Problem 6

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstdbool>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;

struct jihe {
	int first;
	int end;
	int cha;
};
jihe str[50000];
bool cmp(jihe a, jihe b) {
	return a.first < b.first;
}
int main()
{
	int n;
	cin >> n;
	while (n--) {
		int flag = 1;
		int b;
		cin >> b;
		for (int i = 0; i < b; i++) {
			cin >> str[i].first >> str[i].end;
			str[i].cha = str[i].end - str[i].first;
		}
		sort(str, str + b, cmp);
		int max1 = 0;
		for (int i = 0; i < b; i++) {
			if (str[i].cha > max1) {
				max1 = str[i].cha;
			}
		}

		for (int i = 0; i < b; i++) {
			if ((str[i].first + max1 > str[i + 1].first)&&i<=b-2) {
				flag = 0;
				break;
			}
		}
		if(flag==1){
		cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	 


	
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 6