View Code of Problem 6

#include <bits/stdc++.h>
using namespace std;
typedef struct{
	int l;
	int r;
	int len;
}trap;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,flag=1,max=0,now=0;
		cin>>n;
		trap list[n];
		for(int i=0;i<n;i++){
			cin>>list[i].l>>list[i].r;
			getchar();
			list[i].len=list[i].r-list[i].l;
			if(list[i].len>max) max=list[i].len;
		}
		for(int i=0;i<n;i++){
			if(now<=list[i].l&&now+max>=list[i].r&&(i==n-1||now+max<=list[i+1].l)){
				now+=max;
			}
			else{
				flag=0;
				break;
			}
		}
		if(flag==1)	cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
} 

Double click to view unformatted code.


Back to problem 6