Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- sys.setrecursionlimit(4000)
- str_cases = raw_input()
- cases = int(str_cases)
- energy = []
- def is_possible(tsum, rindex, seq):
- if tsum < 0:
- return 0
- if tsum == energy[rindex]:
- seq.append(rindex)
- return 1
- if rindex == 0:
- #print "out of luck"
- return 0
- if is_possible(tsum, rindex-1, seq):
- return 1
- else:
- seq.append(rindex)
- if is_possible(tsum-energy[rindex], rindex-1, seq):
- return 1
- else:
- seq.pop(seq.index(rindex))
- return 0
- for case in range(cases):
- str_first = raw_input()
- (s_N, s_E) = str_first.split(' ')
- N = int(s_N)
- E = int(s_E)
- str_second = raw_input()
- a = [int(x) for x in str_second.split(' ')]
- str_third = raw_input()
- b = [int(x) for x in str_third.split(' ')]
- for elem in energy:
- energy.remove(elem)
- for i in range(N):
- if i > 0:
- old = energy[i-1]
- else:
- old = 0
- energy.append((old*a[i])+b[i])
- seq = []
- out_string = ""
- if is_possible(E, N-1, seq):
- #print "yay"
- seq.sort()
- pseq = [str(elem) for elem in seq]
- out_string = ' '.join(pseq)
- else:
- out_string = "-1"
- print out_string
Add Comment
Please, Sign In to add comment