Last active
January 19, 2016 17:37
-
-
Save LXZE/950a16e4092a395fb36e to your computer and use it in GitHub Desktop.
code hew - interstella
This file contains 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
from itertools import * | |
def powerset(iterable): | |
s = list(iterable) | |
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) | |
f = open("interstellar_input.txt","r") | |
# f = open("in.in","r") | |
w = open("output.txt","w") | |
num = f.readline() | |
for it in range(0,int(num)): | |
star,time = [int(l) for l in f.readline().split()] | |
people = [int(l) for l in f.readline().split()] | |
slow = [int(l) for l in f.readline().split()] | |
set = [] | |
for z in zip(people,slow): | |
if z[1] == 0: | |
set.append((z[0],z[1],z[0]*1.0)) | |
else: | |
set.append((z[0],z[1],z[0]*1.0/z[1])) | |
set = sorted(set,key = lambda tup:tup[2],reverse=True) | |
timeRemain = time-(star+1) | |
helped = 0 | |
for data in set: | |
if timeRemain-data[1] >= 0: | |
helped += data[0] | |
timeRemain-=data[1] | |
print helped | |
# for tup in list(powerset(range(1,len(set)+1)))[1:]: | |
# for num in tup: | |
# timeLeft += set[num-1][1] | |
# if timeLeft > timeRemain: | |
# break | |
# helped += set[num-1][0] | |
# if timeLeft <= timeRemain: | |
# maxHelp = helped | |
# timeLeft = 0 | |
# helped = 0 | |
# print maxHelp | |
w.write("{0}\n".format(helped)) | |
w.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment