View Code of Problem 6

#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
	bool success;
 
	int T,n,i,max;
 
	int trap[100][2];
 
	cin>>T;
 
	while(T--){
		scanf("%d",&n);
 
		for(i=0;i<n;i++){
			cin>>trap[i][0]>>trap[i][1];
		}
		max = 0;
		for(i=0;i<n;i++){//找出最大的陷阱  长度为max
			if(trap[i][1]-trap[i][0]>max)
				max = trap[i][1]-trap[i][0];
		}
		success = true;
		for(i=0;i<n-1;i++){
			if(trap[i][0]+max>trap[i+1][0]){
				success = false;
			}
		}
		if(success)
			cout<<"YES";
		else
			cout<<"NO";
        if(T!=0){
            cout<<endl;
        }
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 6