Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = open('27.txt').readlines()
- n = int(data[0])
- a = []
- for i in range(1, n + 1):
- data[i] = list(map(int, data[i].split()))
- if data[i][1] % 2 == 1:
- a.append(data[i])
- n = len(a)
- a = list(map(sorted, a))
- dp = [{} for i in range(n)]
- sost = [(0, 0), (0, 1), (1, 0), (1, 1)]
- for i in range(n):
- for ost in sost:
- dp[i][ost] = 0
- dp[0][(a[0][0] % 2, a[0][1] % 2)] = sum(a[0])
- for i in range(1, n):
- for ost in sost:
- dp[i][ost] = dp[i - 1][ost]
- x = a[i][0] % 2 #остаток первого в паре
- y = a[i][1] % 2 #остаток второго в паре
- sm = sum(a[i]) #сумма в паре
- for ost in sost:
- x1 = (ost[0] + x) % 2
- y1 = (ost[1] + y) % 2
- dp[i][(x1, y1)] = max(dp[i][(x1, y1)], dp[i - 1][ost] + sm)
- print(dp[-1][(1, 0)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement