Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f = open("27-A.txt")
- #f = open("27-B.txt")
- dataAmount = int(f.readline())
- totalSum = 0
- minDiff = 999999999
- difNow = 0
- minDifs = list()
- for i in range(0, dataAmount):
- buf = list(map(int, f.readline().split()))
- buf.sort()
- totalSum += buf[0] + buf[1]
- #Текущая разница в паре, если взять другое число вместо первого или второго
- difNowFirst = buf[2] - buf[1]
- difNowSecond = buf[1] - buf[0]
- if difNowFirst < minDiff and ((difNowFirst % 3 == 0 and difNowFirst % 17 != 0) or (difNowFirst % 3 != 0 and difNowFirst % 17 == 0)):
- minDiff = difNowFirst
- minDifs.append(difNowFirst)
- if difNowSecond < minDiff and ((difNowSecond % 3 == 0 and difNowSecond % 17 != 0) or (difNowSecond % 3 != 0 and difNowSecond % 17 == 0)):
- minDiff = difNowSecond
- minDifs.append(difNowSecond)
- if (totalSum % 3 == 0 and totalSum % 17 != 0) or (totalSum % 3 != 0 and totalSum % 17 == 0):
- print(totalSum)
- else:
- print(totalSum + minDiff)
- print(minDifs)
- #Как искать несколько минимальных сумм, если результат не подходит?
Add Comment
Please, Sign In to add comment