View Code of Problem 6

#include <stdio.h>

int main(void)
{
	int t,n;
	scanf("%d",&t);
	
	int i ;
	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 = 0; 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