barabar4e

08. Equal Pairs

Oct 14th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. n = int(input())
  2. number = n * 2
  3.  
  4. min_sum = 0
  5. max_sum = 0
  6. constant_sum = 0
  7. current_sum = 0
  8. for i in range(1, number + 1,):
  9.     current_num = int(input())
  10.     if i == 2:
  11.         current_sum += current_num
  12.         constant_sum = current_sum
  13.         min_sum = constant_sum
  14.     elif i % 2 == 0:
  15.         current_sum += current_num
  16.         if min_sum < current_sum:
  17.             max_sum = current_sum
  18.         elif min_sum > current_sum:
  19.             min_sum = current_sum
  20.     else:
  21.         current_sum = 0
  22.         current_sum += current_num
  23. diff = abs(max_sum - min_sum)
  24. if constant_sum == current_sum:
  25.     print(f'Yes, value={constant_sum}')
  26. else:
  27.     print(f'No, maxdiff={diff}')
  28.  
Advertisement
Add Comment
Please, Sign In to add comment