View Code of Problem 6

#include <stdio.h>
#include<string.h>
#include<math.h>

int main()
{
	int t,n,i;
	scanf("%d",&t);
		
	while(t--)
	{
		scanf("%d",&n);
		int a[n][2];
		for(i = 0; i < n;i++)					
			scanf("%d %d", &a[i][0],&a[i][1]);							
		int max = a[0][1] - a[0][0];
		
		for(i = 1; i < n; i++)
		{
			if(max < a[i][1] - a[i][0])			
				max = a[i][1] - a[i][0];			
		}
		
		int p =1;
		
		for(i = 0;i<n-1;i++)
		{
			if(a[i][0]+max<a[i][1]||a[i][0]+max>a[i+1][0])
				
				p = 0;		
		}
		
		if(p == 1)		
			printf("YES\n");		
		else		
			printf("NO\n");

	}	
	return 0;	
 } 

Double click to view unformatted code.


Back to problem 6