Array ( [0] => [1] => questions [2] => Popular-Algorithms [3] => Piles-of-Stone )
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.
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.
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.
4 1 2 3 2 4 3 2 5 6 5 2 4 2 6 2 6 5 2 12 1
YES NO YES NO
3 1 3 4 3 5 2 3 4 5 3 3 4 3 2 5
YES NO NO
4 45 32 33 24 39 10 20 30 20 40 10 29 38 47 56 1 92 83 74 65
NO YES NO NO
Login to see Discussion
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.
Login to see Solution