# 27

Jun 19th, 2021 (edited)
202
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. f = open("27-B.txt", 'r')
3. count_pair = 0
4. count_dispair = 0
5. ans = 0
6. diff_pair = 10000000
7. diff_dispair = 10000000
8. for i in range(n):
10.     arr.sort()
11.     ans += arr[0]
12.     if arr[0] % 2 == 0:
13.         count_pair += 1
14.     else:
15.         count_dispair += 1
16.     diff_curr = arr[1] - arr[0]
17.     if diff_curr < diff_dispair and diff_curr % 2 != 0:
18.         diff_dispair = diff_curr
19.
20.     if diff_curr < diff_pair and diff_curr % 2 == 0:
21.         diff_pair = diff_curr
22.
23. if count_pair > count_dispair:
24.     if ans % 2 != 0:
25.         if count_pair - 1 > count_dispair + 1:
26.             ans += diff_dispair
27.         else:
28.             ans += diff_pair
29. if count_pair < count_dispair:
30.     if ans % 2 == 0:
31.         if count_pair - 1 < count_dispair + 1:
32.             ans += diff_dispair
33.         else:
34.             ans += diff_pair
35. print(ans)
36.
RAW Paste Data