python/CodeChallenge_19.py

34 lines
1.5 KiB
Python

'''
Bob has three sisters: Ann, Bella, and Caroline. They're collecting coins. Currently, Ann has a coins, Bella has b coins and Caroline has c coins. Recently Bob has
returned from the trip around the world and brought n coins. He wants to distribute all these n coins between his sisters in such a way that the number of coins Ann
has is equal to the number of coins Bella has and is equal to the number of coins Caroline has. In other words, if Bob gives A coins to Ann, B coins to Bella and C
coins to Caroline A+B+C=n, then a+A=b+B=c+C
Note that A, B or C (the number of coins Bob gives to Ann, Bella and Caroline correspondingly) can be 0. Help Bob to find out if it is possible to distribute all n
coins between sisters in a way described above.
Given an integers a - the number of coins Ann has , b - number of coins Bella has, c - number of coins Caroline has and n - the number of coins Bob has.
Return YES if Bob can distribute all n coins between his sisters and NO in the opposite case.
Example 1
Input:
a = 3, b = 798, c = 437, n = 1804
Output:
YES
'''
class Solution(object):
def solve(self,a:int, b:int, c:int, n:int) -> str:
print(f"a: {a}, b: {b}, c: {c}, n: {n}")
total = a + b + c + n
if total % 3 == 0:
target = total // 3
if target >= a and target >= b and target >= c:
return "YES"
return "NO"
s = Solution()
# Example usage
print(s.solve(3, 798, 437, 1804)) # Output: YES
print(s.solve(1, 2, 3, 4)) # Output: NO