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 = [[0 for i in range(4)] for j in range(n)]
- dp[0][(a[0][0] % 2) * 2 + (a[0][1] % 2)] = sum(a[0])
- for i in range(1, n):
- for ost in range(4):
- dp[i][ost] = dp[i - 1][ost]
- x = a[i][0] % 2 #остаток первого в паре
- y = a[i][1] % 2 #остаток второго в паре
- sm = sum(a[i]) #сумма в паре
- for ost in range(4):
- x1 = (ost // 2 + x) % 2
- y1 = (ost % 2 + y) % 2
- dp[i][x1 * 2 + y1] = max(dp[i][x1 * 2 + y1], dp[i - 1][ost] + sm)
- print(dp[-1][2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement