View Code of Problem 6

#include<stdio.h>

typedef struct trap{
    int l,r;
}trap;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        int flag=1;
        int step=0;
        trap tp[10000];
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d%d",&tp[i].l,&tp[i].r);
            if(step<tp[i].r-tp[i].l) step = tp[i].r-tp[i].l;
        }
        int sum=tp[0].l;
        for(int j=0;j<n-1;j++){
            sum+=step;
            if(sum>tp[j+1].l){
                flag=0;
                break;
            }
        }
        printf("%s\n",flag?"YES":"NO");
    }

    return 0;
}

Double click to view unformatted code.


Back to problem 6