I was trying a different approach, it makes slices of the sorted list and
then checks if its possible or not
def findSol(arr, budget):
if min(arr) > budget:
return 0
arr.sort()
for i in range(len(arr)-1, -1, -1):
temp = arr[0:i]
temp2 = arr[0:i+1]
#print("First slice : ", temp)
#print("Second slice : ", arr[0:i+1])
if sum(temp) <= budget and sum(temp2) > budget:
#print("Got executed !")
return len(temp)
def main():
t = int(input())
output = []
while t > 0:
num_and_budget = input().split()
num_and_budget = list(map(int, num_and_budget))
budget = num_and_budget[1]
items = input().split()
items = list(map(int, items))
output.append(findSol(items, budget))
t -= 1
for i in range(len(output)):
print("Case #" + str(i+1) + ": " + str(output[i]))
main()
But It's giving WA on googles machine, though it gives correct output in
local machine...Can someone spot some Bug ?? PLZ
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/ab6d0500-2728-47ba-8d53-449bcb6f63b8%40googlegroups.com.