View Code of Problem 6

#include<iostream>

using namespace std;

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int step[50000]={0};
        int n;
        cin>>n;
        int jump;
        for(int i=0;i<n;i++)
        {
            int l,r;
            cin>>l>>r;
            for(int j=l+1;j<r;j++)
            {
                step[j]=1;
            }
            if(i==0)
                jump=r-l;
        }
        int t=0;
        while(true)
        {
            t+=jump;
            if(step[t])
            {
                cout<<"NO"<<endl;
                break;
            }
            if(n==0)
            {
                cout<<"YES"<<endl;
                break;
            }
            n--;
        }
    }
}
#include<iostream>

using namespace std;

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int step[50000]={0};
        int n;
        cin>>n;
        int jump;
        for(int i=0;i<n;i++)
        {
            int l,r;
            cin>>l>>r;
            for(int j=l+1;j<r;j++)
            {
                step[j]=1;
            }
            if(i==0)
                jump=r-l;
        }
        int t=0;
        while(true)
        {
            t+=jump;
            if(step[t])
            {
                cout<<"NO"<<endl;
                break;
            }
            if(n==0)
            {
                cout<<"YES"<<endl;
                break;
            }
            n--;
        }
    }
  return 0;
}

/*
Main.cc: In function 'int main()':
Main.cc:48:5: error: redefinition of 'int main()'
 int main()
     ^
Main.cc:5:5: note: 'int main()' previously defined here
 int main()
     ^
*/

Double click to view unformatted code.


Back to problem 6