Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Painting Wall by htamas
from itertools import accumulate
def painted(ranges):
last = counter = total = 0
for pos, d in sorted(sum((((i-1, +1), (j, -1)) for (i, j) in ranges), ())):
if counter:
total += pos - last
counter += d
last = pos
return total
def checkio(num, ranges):
for i, prefix in enumerate(accumulate([i] for i in ranges), start=1):
if painted(prefix) >= num:
return i
return -1
Feb. 27, 2014
Comments: