Last active
March 7, 2018 21:35
-
-
Save michaelasper/9f42ed5fdc2f8824f33280cae0fe59dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def maxusers(locations, weights, m): | |
n = len(locations) - 1 | |
P = [0] * (n+1) | |
prev = [0] * (n+1) | |
P[0] = 0 | |
i = 1 | |
j = 2 | |
while(j <= n): | |
if locations[j] - locations[i] >= m: | |
prev[j] = i | |
if i + 1 < j: | |
i += 1 | |
continue | |
j += 1 | |
for i in range(n+1): | |
P[i] = max(weights[i] + P[prev[i]], P[i-1]) | |
return P[n] | |
print(maxusers([-1, 0, 3, 4, 8, 9, 10, 14], [-1, 10, 15, 8, 5, 60, 45, 10], 4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment