Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test1 = True
- test2 = True
- def main():
- inputs = ["a_example.in", "b_small.in", "c_medium.in", "d_quite_big.in", "e_also_big.in"]
- for x in inputs:
- f = open(x)
- slices_all, pizzas = f.readline().split()
- slices = list(map(int, (f.readline().split())))
- out = solve(slices_all,slices)
- out.reverse()
- print(len(out) , "\n", *out)
- out_name, b= x.split(".")
- out_f = open(out_name + ".out", 'w')
- out_f.write(str(len(out)) + '\n')
- for x in out:
- out_f.write(str(x) + " ")
- out_f.close()
- def solve(sum, slices):
- global test1
- global test2
- out = []
- score = 0
- i = len(slices) -1
- while i>=0 and test1:
- temp_out = []
- curr_sum = 0
- j=i
- while j>=0 and test2:
- tmp = slices[j]
- if curr_sum + tmp < int(sum):
- curr_sum += tmp
- temp_out.append(j)
- elif curr_sum + tmp == int(sum):
- curr_sum += tmp
- temp_out.append(j)
- test2 = False
- test1 = False
- j -= 1
- if curr_sum > score:
- score = curr_sum
- out = temp_out
- if len(out) == len(slices):
- test1 = False
- i -= 1
- print(score)
- return out
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement