Pressing and Glittering Records
Time limit3sMemory limit128 MB
Pick k pressing days and k glittering days over n days so each press day precedes its glitter day at minimum total cost.
Problem
A rapper is producing a special vinyl edition of his album. Every record must first be pressed at a pressing plant, and only then coated with glitter at a glitter shop before it is finished.
The rapper has a contract to make exactly records. The pressing plant and the glitter shop can each handle only one record per day. Every record must be pressed before it is glittered, but the same record may be both pressed and glittered on a single day. A record that has been pressed but not yet glittered can be stored for as long as needed at no extra cost.
For each of the next days you are given that day's pressing cost and glittering cost. Decide on which days to press and on which days to glitter so that all records are finished at the minimum possible total cost.
Input
The first line contains two integers and ().
The second line contains positive integers, each at most ; the -th value is the pressing cost on day .
The third line contains positive integers, each at most ; the -th value is the glittering cost on day .
Output
Print a single integer: the minimum total cost to produce glitter-coated records.
Hint
For the sample input, one optimal plan is: press and glitter the first record on day 1; press the second record on day 2 and glitter it on day 4; press the third record on day 3 and glitter it on day 5; press the fourth record on day 6 and glitter it on day 8. The total cost is 32.