CodechefMay 10, 2025

Weights

Hazrat Ali

Codechef

Chef is playing with weights. He has an object weighing WW units. He also has three weights each of X,Y,X,Y, and ZZ units respectively. Help him determine whether he can measure the exact weight of the object with one or more of these weights.

If it is possible to measure the weight of object with one or more of these weights, print YES, otherwise print NO.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases.
  • Each test case consists of single line containing a four positive integers W,X,Y,W,X,Y, and ZZ.

Output Format

For each test case, output on a new line YES if it is possible to measure the weight of object with one or more of these weights, otherwise print NO.

You may print each character of the string in either uppercase or lowercase (for example, the strings yesYESYes, and yeS will all be treated as identical).

Constraints

  • 1≤T≤104
  • 1≤W,X,Y,Z≤105

Sample 1:

Input
 
4
5 2 1 6
7 9 7 2
20 8 10 12
20 10 11 12
Output
NO
YES
YES
NO

Solution
for i in range(int(input())):
    (W, X, Y, Z) = map(int, input().split(' '))
    if X==W or Y==W or Z==W:
        print("YES")
    elif (X+Y) == W or (X+Z) == W or (Y+Z)==w or (X+Y+Z) ==W:
        print("YES")
    else:
        print("NO")


 

Comments