Equal Coins EQUALCOIN Solution Codechef

Equal Coins EQUALCOIN Solution

Chef has XX coins worth 11 rupee each and YY coins worth 22 rupees each. He wants to distribute all of these X+YX+Y coins to his two sons so that the total value of coins received by each of them is the same. Find out whether Chef will be able to do so.

Input Format

  • The first line of input contains a single integer TT, denoting the number of testcases. The description of TT test cases follows.
  • Each test case consists of a single line of input containing two space-separated integers XX and YY.

Output Format

For each test case, print “YES” (without quotes) if Chef can distribute all the coins equally and “NO” otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints

  • 1≤T≤1031≤T≤103
  • 0≤X,Y≤1080≤X,Y≤108
  • X+Y>0X+Y>0

Subtasks

  • Subtask 1 (100 points): Original constraints

Sample Input 1 

4
2 2
1 3
4 0
1 10

Sample Output 1 

YES
NO
YES
NO

Explanation

Test case 11: Chef gives each of his sons 11 coin worth one rupee and 11 coin worth two rupees.

Test case 33: Chef gives each of his sons 22 coins worth one rupee.

SOLUTION

Program Python: Equal Coins EQUALCOIN Solution in Python

for _ in range(int(input())):
    x,y=map(int,input().split())
    if x%2==0:
        if x==0 and y%2==0:
            print("YES")
        elif x==0 and y%2!=0:
            print("NO")
        else:
            print("YES")
    else:
        print("NO")

Program C++: Equal Coins EQUALCOIN Solution in C++

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        long long x,y;
        cin >> x >> y;
        if(x == 0 && y%2 != 0) {
            cout << "NO" << endl;
        }
        else if((x+(2*y)) % 2 == 0) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
}

Program Java: Equal Coins EQUALCOIN Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	Scanner sc=new Scanner(System.in);
	int t;
	t=sc.nextInt();
	while(t-->0)
	{
	    int a,b;
	    a=sc.nextInt();
	    b=sc.nextInt();
	    int tot=a*1+b*2;
	    if(a%2==1)
	    System.out.println("NO");
	    else if(a%2==0 && b%2==0)
	    System.out.println("YES");
	    else if(a>1)
	    System.out.println("YES");
	    else
	    System.out.println("NO");
	    
	}
	}
}

November Long Challenge 2021 Solution

Codechef Long Challenges Solution

October Long Challenge 2021 Solution

September Long Challenge 2021 Solution

Leave a Comment