Advertisement
veronikaaa86

02. Half Sum Element

Jul 24th, 2022
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import sys
  2.  
  3. n = int(input())
  4.  
  5. max_num = -sys.maxsize
  6. sum = 0
  7. for i in range(1, n + 1):
  8.     current_num = int(input())
  9.  
  10.     sum = sum + current_num
  11.  
  12.     if current_num > max_num:
  13.         max_num = current_num
  14.  
  15. other_nums_sum = sum - max_num
  16.  
  17. if other_nums_sum == max_num:
  18.     print("Yes")
  19.     print(f"Sum = {max_num}")
  20. else:
  21.     print("No")
  22.     diff = abs(other_nums_sum - max_num)
  23.     print(f"Diff = {diff}")
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement