DialOG_

Untitled

Apr 11th, 2021
426
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2.  
  3. d11=d12=d21=d22=20001
  4. res=0
  5.  
  6. for i in range(0,n):
  7.     a, b = map(int,input().split())
  8.  
  9.     if a > b:
  10.         res+=b
  11.     else:
  12.         res+=a
  13.  
  14.     if (abs(a-b)%3 == 1) and (abs(a-b)<d11):
  15.         d12=d11
  16.         d11 = abs(a-b)
  17.     elif (abs(a-b)%3 == 1) and (abs(a-b)<d12):
  18.         d12 = abs(a-b)
  19.     if abs(a-b)%3 == 2 and abs(a-b)<d21:
  20.         d22=d21
  21.         d21 = abs(a-b)
  22.     elif abs(a-b)%3 == 2 and abs(a-b)<d22:
  23.         d22 = abs(a-b)
  24.  
  25.    
  26. if res %3==0:
  27.     print(res)
  28. elif res%3==1:
  29.     if res+d21<res+d11+d12:
  30.         print(res+d21)
  31.     else:
  32.         print(res+d11+d12)
  33. elif res%3==2:
  34.     if res+d11<res+d21+d22:
  35.         print(res+d11)
  36.     else:
  37.         print(res+d21+d22)
  38.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×