Created
October 21, 2015 13:53
-
-
Save lwander/42e2f4fd8cb4832ee1e9 to your computer and use it in GitHub Desktop.
easy_partition
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
easy_partition(keys, T) | |
B = [] | |
A = [] | |
B_s = 0 | |
A_s = 0 | |
keys = sort(keys) | |
while len(keys) > 0 | |
k = pop_biggest(keys) | |
if B_s + k > T: | |
if A_s + k > T: | |
return ([], []) | |
else: | |
A.push(k) | |
A_s += k | |
else: | |
B.push(k) | |
B_s += k | |
return (A, B) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment