veronikaaa86

02. Half Sum Element

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