Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created July 18, 2014 13:01
Show Gist options
  • Save cocodrips/5fcbe15d6839410d475d to your computer and use it in GitHub Desktop.
Save cocodrips/5fcbe15d6839410d475d to your computer and use it in GitHub Desktop.
SRM624 Div1 Easy in python
class BuildingHeights:
""" 4000 ** 2 -> T L E"""
def minimum(self, heights):
N = len(heights)
heights = list(heights)
heights.sort()
sums = [0 for _ in xrange(N+1)]
for i in xrange(N):
sums[i+1] = sums[i] + heights[i]
result = 0
for n in xrange(2, N + 1):
mini = 1000000000
for l in xrange(N - n + 1):
mini = min(mini, heights[l + n - 1] * n - (sums[l + n] - sums[l]))
result ^= mini
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment