Skip to content

Commit b64204e

Browse files
authored
Create luck_balance.py
1 parent 26e938c commit b64204e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

luck_balance.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# https://www.hackerrank.com/challenges/luck-balance
2+
3+
n,k= input().strip().split()
4+
n,k = int(n),int(k)
5+
count = 0
6+
impContest = []
7+
for _ in range(n):
8+
L,T = input().strip().split()
9+
L,T = int(L),int(T)
10+
if T == 0:
11+
count += L
12+
else:
13+
impContest.append(L)
14+
impContest.sort()
15+
size = len(impContest)-k
16+
newList = impContest[size:]
17+
luckNegative = impContest[:size]
18+
count+= sum(newList) - sum(luckNegative)
19+
20+
if size < 0:
21+
print(count+sum(impContest)-sum(newList)+sum(luckNegative))
22+
else:
23+
print(count)
24+
25+
26+
27+
28+

0 commit comments

Comments
 (0)