g0g00z

Untitled

Jul 26th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. pairs_count = int(input())
  2.  
  3. min_sum = 0
  4. max_sum = 0
  5. current_sum = 0
  6. diff = []
  7. # collects the sum of each pair
  8. for i in range(pairs_count):
  9.     num1 = int(input())
  10.     num2 = int(input())
  11.  
  12.     current_sum = num1 + num2
  13.  
  14.     diff.append(current_sum)
  15.  
  16. # initiates a variable that will hold the maximum difference between two adjacent pairs
  17. max_difference = float('-inf')
  18.  
  19. # loops through the sum of pairs
  20. for pair in range(1, len(diff)):
  21.     current_pair = diff[pair]
  22.     previous_pair = diff[pair - 1]
  23.  
  24.     # calculate the difference between two adjacent pairs
  25.     absolute_difference = abs(current_pair - previous_pair)
  26.  
  27.     # records the max difference if the absolute adjacent pairs difference is the highest so far encountered
  28.     if absolute_difference > max_difference:
  29.         max_difference = absolute_difference
  30.  
  31. # this is for the case where we only have one pair
  32. if len(diff) == 1:
  33.     print(f"Yes, value={diff[0]}")
  34. # if we have more than one pair ...
  35. else:
  36.     # if the absolute max difference is 0 means that pairs are all equal and we can print any of the sum of pairs
  37.     if max_difference == 0:
  38.         print(f"Yes, value={diff[0]}")
  39.     # if they are not equal print the max difference
  40.     else:
  41.         print(f"No, maxdiff={max_difference}")
  42.  
Advertisement
Add Comment
Please, Sign In to add comment