first input will be number of test cases t
, then given two numbers a
and b
you have to perform i
operations such that,
- add 1 to
a
ifi
is odd - add 2 to
a
ifi
is even
now print YES if a
can become equal to b
and NO if it can't
when I tried to submit my solution i
got error that time limit is exceeded.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t, a, b;
cin >> t;
while (t)
{
cin >> a >> b;
int flag = 1;
while (a != b && a < b)
{
if (flag % 2 == 0)
{
a += 2;
}
else
{
a += 1;
}
flag++;
}
if (a == b)
cout << "YES" << endl;
else
cout << "NO" << endl;
t--;
}
return 0;
}