Train Merge Advanced

Problem #235

Tags: puzzle arrays c-1 c-0

Who solved this?

No translations... yet

Once again we thank Clive Fraser aka CSFPython who suggested both versions of this curious problem!

As a small improvement over the previous Train Merge, let us now not only calculate minimum sum jump height, but also produce "instruction" for railroad worker about the order in which cars should be coupled.

Input data
First line has single value - number of cars in each train.
Next line has label TrainA.
Then some lines follow with heights of cars of the 1st train, split to about 20 values per line.
Next line with label TrainB follows.
And again, heights of cars are given in several lines.

Answer should give minimum total jump height again, and then the string consisting of letters a and b, denoting order of cars (generally there may be several variants - pick any).

Example:

input:
5
TrainA
61 89 45 71 93
TrainB
52 73 72 85 3

answer:
212 aaababbbab
You need to login to get test data and submit solution.