Advertisement
DialOG_

Untitled

Apr 12th, 2021
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. n = int(input())
  2. res = 0
  3. c0 = 0
  4. c1 = 0
  5. o1 = o2 = e1 = e2 = 20001
  6.  
  7. for i in range(0, n):
  8.     a, b = map(int, input().split())
  9.     if a>b:
  10.         res+=a
  11.     else:
  12.         res+=b
  13.  
  14.     if abs(a-b) % 2 == 0:
  15.         if abs(a-b) < o1:
  16.             o2 = o1
  17.             o1 = abs(a-b)
  18.         elif abs(a-b) < o2:
  19.             o2 = abs(a-b)
  20.     else:
  21.         if abs(a-b) < e1:
  22.             e2 = e1
  23.             e1 = abs(a-b)
  24.         elif abs(a-b) < e2:
  25.             e2 = abs(a-b)
  26.  
  27. if res % 2 == 0:
  28.     if c1 > c0:
  29.         print(res)
  30.     else:
  31.         if res-o1>res-e1-e2:
  32.             print(res-o1)
  33.         else:
  34.             print(res-e1-e2)
  35. else:
  36.     if c0>c1:
  37.         print(res)
  38.     else:
  39.         if res-e1>res-o1-o2:
  40.             print(res-e1)
  41.         else:
  42.             print(res-o1-o2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement