View Code of Problem 6

#include<iostream>

using namespace std;

int main()
{
	int T, n;
	cin >> T;
	if(T == 0)
	{
		return 0;
	}
	while (T--)
	{
		cin >> n;
		if(n == 0)
		{
			return 0;
		}
		int flag = 1,are;
		int l, r;
		cin >> l;
		cin >> r;
		are=r;
		int temp = r - l;
		while (--n)
		{
			int ll,rr;
			cin >> ll;
			cin >> rr;
			if((ll-are)%temp!=0)
			{
				cout<<"NO\n";
			}
			int out = rr - ll;
			if (out != temp)
			{
				flag = 0;
			}
			are=rr;
		}
		if (flag == 0)
		{
			cout << "NO\n";
		}
		else
		{
			cout << "YES\n";
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 6