프로그래밍/HackerRank
[HackerRank][Python3] Luck Balance
snoopybox
2018. 7. 15. 22:59
Problem :
https://www.hackerrank.com/challenges/luck-balance/problem
My Solution :
#!/usr/bin/env python3
def luckBalance(k, contests):
T0, T1 = [], []
for L, T in contests:
if T == 1:
T1.append(L)
else:
T0.append(L)
T1.sort(reverse=True)
return sum(T1[:k]) - sum(T1[k:]) + sum(T0)
n, k = map(int, input().split())
contests = []
for _ in range(n):
contests.append(list(map(int, input().rstrip().split())))
result = luckBalance(k, contests)
print(result)