-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLuck Balance
More file actions
48 lines (37 loc) · 869 Bytes
/
Copy pathLuck Balance
File metadata and controls
48 lines (37 loc) · 869 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the luckBalance function below.
def luckBalance(k, contests):
imp = []
luck = 0
for i,j in contests:
if j==0:
luck += i
print(luck)
else:
imp.append(i)
imp.sort(reverse = True)
for i in imp:
print(i)
if k>=len(imp):
k = len(imp)
for i in range(0,k):
luck += imp[i]
for i in range(k,len(imp)):
luck -= imp[i]
return luck
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nk = input().split()
n = int(nk[0])
k = int(nk[1])
contests = []
for _ in range(n):
contests.append(list(map(int, input().rstrip().split())))
result = luckBalance(k, contests)
fptr.write(str(result) + '\n')
fptr.close()