Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created October 29, 2013 13:23
Show Gist options
  • Save cocodrips/7214554 to your computer and use it in GitHub Desktop.
Save cocodrips/7214554 to your computer and use it in GitHub Desktop.
SRM588 Div2 500
import itertools
class GUMIAndSongsDiv2:
def maxSongs(self, duration, tone, T):
duration_tones = []
for i, d in enumerate(duration):
duration_tones.append((tone[i], d))
duration_tones.sort()
n = 0
for i in xrange(1, len(duration_tones) + 1):
for duration_tone in itertools.combinations(duration_tones, i):
accumulate_time = 0
for index, tuple in enumerate(duration_tone):
accumulate_time += tuple[1]
if index >= 1:
accumulate_time += duration_tone[index][0] - duration_tone[index-1][0]
if accumulate_time <= T:
n = i
break
else:
break
return n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment