View Code of Problem 6

#include <stdio.h>

int main(int argc, char* argv[])
{
	int n;
	scanf("%d",&n);
	while ((n--)>0){
		int t,step=1,d;
		scanf("%d",&t);
		int a[100],b[100];
		int i;
		for (i=0;i<t;i++){
			scanf("%d%d",&a[i],&b[i]);
		}
		int s;
		s=b[0]-a[0];
		d=s;
		for (i=1;i<t;i++){
			d+=s;
			if (d>=b[i]){
				if (i+1==t){
				step++;
				}
				else if (d<=a[i+1]){
				step++;
				}
				else {
				step=1;
				break;
				}
			}
			else{
				step=1;
				break;
			}
		}
		/*for (s=b[0]-a[0];s<=a[1]-a[0];s++){
			d=s;
			for (i=1;i<t-1;i++){
			if (d>=b[i-1]&&d<=a[i]){
				d+=d;
				step=d/s;
			}
			else {
				step=0;
				break;
			}	
			}
			if (step==t)
				break;
		}
		*/
		if (step==t) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 6