Last active
January 10, 2016 04:03
-
-
Save whatalnk/b837ffd4cc572fb9be43 to your computer and use it in GitHub Desktop.
TopCoder SRM 669 Div2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LiveConcert(): | |
def maxHappiness(self, h, s): | |
dict = {} | |
m = len(h) | |
for (key, val) in zip(s, h): | |
if dict.has_key(key): | |
dict[key].append(val) | |
else: | |
dict[key] = [val] | |
happiness = 0 | |
for val in dict.itervalues(): | |
happiness += max(val) | |
return happiness |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
class CombiningSlimes(): | |
def maxMascots(self, a): | |
mascots = 0 | |
aa = deque(sorted(a)) | |
while len(aa) != 1: | |
l = aa.popleft() | |
r = aa.pop() | |
aa.append(l+r) | |
mascots += l*r | |
return(mascots) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment