View Code of Problem 6

#include<cstdio>
#include<vector>
using namespace std;
typedef struct trap{
	int l,r;
}trap;
int main(){
	//freopen("6.txt","r",stdin);
	int t,n;
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		int flag=1,step=0;
		scanf("%d",&n);
		vector<trap> vt(n+1);
		for(int j=0;j<n;j++){
			scanf("%d %d",&vt[j].l,&vt[j].r);
			if(step<vt[j].r-vt[j].l)	step=vt[j].r-vt[j].l;
		}
		int sum=vt[0].l;
		for(int j=0;j<n-1;j++){
			sum+=step;
			if(sum>vt[j+1].l){
				flag=0;
				break;
			}
		}
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 6