View Code of Problem 6

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;



int main()
{
    #ifdef  ONLINE_JUDGE
    #else
    freopen("1.txt","r",stdin);
    #endif
    int k;
    cin>>k;
    while(k--)
    {
        int n;
        cin>>n;
        int a[n],b[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
        int maxjump=b[0]-a[0];
        for(int i=1;i<n;i++)
        {
            int temp=b[i]-a[i];
            maxjump=max(temp,maxjump);
        }
        bool flag=1;
        int ans;
        for(int i=0;i<n;i++)
        {
            ans=a[i];
            if(ans+maxjump<b[i]||(i+1<n&&ans+maxjump>a[i+1]))
            {
                flag=0;
                break;
            }
        }
        if(flag==1) cout<<"YES";
        else cout<<"NO";
        if(k>0) cout<<endl;
    }



    return 0;
}

Double click to view unformatted code.


Back to problem 6