Array ( [0] => [1] => questions [2] => HackwithInfy-Previous-Questions [3] => Piles-of-Stone ) HackwithInfy Previous Questions | Piles of Stone | THE INQUISITIVE





Piles of Stone

LEVEL:Beginner

Description

There are three piles of stones. The first pile contains a stones, the second pile contains b stones and the third pile contains c stones. You must choose one of the piles and split the stones from it to the other two piles; specifically, if the chosen pile initially contained s stones, you should choose an integer k (0?k?s), move k stones from the chosen pile onto one of the remaining two piles and s?k stones onto the other remaining pile. Determine if it is possible for the two remaining piles (in any order) to contain x stones and y stones respectively after performing this action.

Input Format

The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first and only line of each test case contains five space-separated integers a,b,c, x and y.

Output Format

For each test case, print a single line containing the string "YES" if it is possible to obtain piles of the given sizes or "NO" if it is impossible.


Example 1:

Input
4
1 2 3 2 4
3 2 5 6 5
2 4 2 6 2
6 5 2 12 1
Output
YES
NO
YES
NO
Example 2:

Input
3
1 3 4 3 5
2 3 4 5 3
3 4 3 2 5
Output
YES
NO
NO
Example 3:

Input
4
45 32 33 24 39
10 20 30 20 40
10 29 38 47 56
1 92 83 74 65
Output
NO
YES
NO
NO

oops

Login to see Discussion




Approach

Return False if sum of a,b,c is not equal to x+y as sum of stones should be equal before and after shifting.
Return False if minimum of a,b,c is greater than x or y.
In all other cases True can be returned


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution