-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathluck-balance.py
More file actions
30 lines (25 loc) · 844 Bytes
/
luck-balance.py
File metadata and controls
30 lines (25 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/python3
import sys
def luckBalance(n, k, arr):
res = sum(list(map(lambda x: x[0], filter(lambda x: x[1] == 0, arr))))
arr = sorted(arr, key=lambda x: (-x[1], -x[0]))
important = len(list(filter(lambda x: x[1] == 1, arr)))
kcnt = 0
for ind in range(important):
#print("res = {} adding {}".format(res, arr[ind][0]))
if kcnt < k:
res += arr[ind][0]
kcnt += 1
else:
res -= arr[ind][0]
#print(arr)
return res
if __name__ == "__main__":
n, k = input().strip().split(' ')
n, k = [int(n), int(k)]
contests = []
for contests_i in range(n):
contests_t = [int(contests_temp) for contests_temp in input().strip().split(' ')]
contests.append(contests_t)
result = luckBalance(n, k, contests)
print(result)