Skip to content

Instantly share code, notes, and snippets.

@Eunsol-Lee
Last active January 16, 2017 01:32
Show Gist options
  • Save Eunsol-Lee/acf7d0156ef4eaacad553a7fa16dee78 to your computer and use it in GitHub Desktop.
Save Eunsol-Lee/acf7d0156ef4eaacad553a7fa16dee78 to your computer and use it in GitHub Desktop.
def solve():
(n, m) = map(lambda x: int(x), input().split())
now = [];
cost = 0
for i in range(n):
c = list(map(lambda x: int(x), input().split()))
c.sort()
count = 0
for x in c:
count += 1
value = count ** 2 + x - (count - 1) ** 2
now.append(value)
now.sort()
cost += now.pop(0)
return cost
T = int(input())
for i in range(1, T+1):
print ('Case #%d: %d'% (i, solve()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment