Advertisement
Spocoman

02. Half Sum Element

Dec 24th, 2021 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. n = int(input())
  2. sum = 0
  3. max_num = 0
  4. for i in range(n):
  5.     num = int(input())
  6.     sum += num
  7.     if num > max_num:
  8.         max_num = num
  9.  
  10. result = sum - max_num
  11. if max_num == result:
  12.     print('Yes')
  13.     print(f'Sum = {max_num}')
  14. else:
  15.     print('No')
  16.     print(f'Diff = {abs(max_num - result)}')
  17.  
  18.  
  19. Pешение c list():
  20.  
  21. n = int(input())
  22. numbers = list()
  23.  
  24. for i in range(n):
  25.     numbers.append(int(input()))
  26.  
  27. if max(numbers) * 2 == sum(numbers):
  28.     print(f'Yes\nSum = {max(numbers)}')
  29. else:
  30.     print(f'No\nDiff = {abs(max(numbers) * 2 - sum(numbers))}')
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement