View Code of Problem 6

#include <stdio.h>
typedef struct node {
 
  int l,r;
}node;
 
int main(){
  int t;
  scanf("%d",&t);
  while(t--){
    int i,maxlen=0,n;
    scanf("%d",&n);
    node hook[50000];
    int flag=1;
    for(i=0; i < n; i++){
      scanf("%d%d",&hook[i].l,&hook[i].r);
      if(maxlen < hook[i].r-hook[i].l)
        maxlen = hook[i].r-hook[i].l;
    }
    int sum=hook[0].l;
    for(i=0; i < n-1; i++){
      sum +=maxlen;
      if(sum > hook[i+1].l){
        flag=0;
        break;
      }
    }
    if(flag== 1)
      printf("YES");
    else
      printf("NO");
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 6