ENOC2 - Editorial

Problem Links :

Practice : Click here
Contest : Click here

Author : Soham Chakrabarti
Tester : Arkapravo Ghosh
Editorialist : Soham Chakrabarti

Difficulty :

Easy

PREREQUISITES:

Observation, Math

PROBLEM:

You are given two numbers A and B and you can do the following operations on them.

  • A can be incremented to 2A
  • B can be decremented to B−2

By doing these operations any number of times (including zero). Can A and B be made equal ?

EXPLANATION:

Observation is important.

As we can see that A can only be incremented and B can only be decremented in the above operations.

We can print a NO for all A > B cases.

Next, coming to the logic. (Assume A <= B, here) :-

  • A and B both are even, always a YES

  • A and B both are odd, always a YES

  • A is even, B is odd, always a NO

  • A is odd, B is even, here we have to consider two cases :-

    • If (B >= 2A ), always a YES ( Example A = 5, B = 10 and above )

    • else always a NO ( Example A = 5, B = 8 )

PSEUDO CODE:

TC{
  int a, b;
  cin >> a >> b;
  if(a > b){
cout << "NO" << '\n';
continue;
  }
  if(a%2 == 0 && b%2 == 0){
cout << "YES" << '\n';
  }
  else if(a%2 == 0 && b%2){
cout << "NO" << '\n';
  }
  else if(a%2 && b%2){
cout << "YES" << '\n';
  }
  else{
if(b >= 2 * a) cout << "YES" << '\n';
else cout << "NO" << '\n';
  }
}

LINKS:

Author’s Solution : Click here :white_check_mark:

Tester’s Solution : Click here :white_check_mark:

2 Likes