#P10712. Optimal Bomb Delivery Route

    ID: 12744 Type: Default 1000ms 256MiB

Optimal Bomb Delivery Route

Optimal Bomb Delivery Route

You are a bomb truck driver. There are \(n\) bomb factories and \(n\) mines located on a line. The coordinates of the factories are given by \(a_1,a_2,\dots,a_n\) and the coordinates of the mines are given by \(b_1,b_2,\dots,b_n\). All coordinates are distinct.

You must pick up exactly one bomb from each factory and deliver it to one of the mines. Initially, you are at coordinate \(0\) and your truck is empty. The truck has a capacity of \(c\) bombs, so you can never hold \(c+\!\!1\) bombs at once. You can perform two types of operations:

  • pickup(x): Drive from your current position to a factory at \(x\). This operation can only be executed if \(x=a_i\) for some \(i\) and your truck is carrying at most \(c-1\) bombs. Note that if the truck is carrying bombs, you must pay a cost equal to \(|x-y|\) when moving from a point \(x\) to \(y\); however, driving with an empty truck is free.
  • offload(x): Drive from your current position to a mine at \(x\). This operation can only be executed if \(x=b_j\) for some \(j\) and your truck is carrying at least one bomb.

When moving while carrying at least one bomb, you must pay an amount equal to the distance traveled. When moving with an empty truck, no cost is incurred. Your goal is to plan a sequence of operations that delivers all bombs while minimizing the total cost.

Note: Although you can carry multiple bombs at once (up to \(c\)), the cost for any move with at least one bomb is just the absolute distance traveled, regardless of the number of bombs on board.

inputFormat

The input consists of three lines.

  1. The first line contains two integers \(n\) and \(c\) \( (1 \le n \le 100,\; 1 \le c \le n)\), where \(n\) is the number of factories (and mines) and \(c\) is the maximum capacity of bombs the truck can carry.
  2. The second line contains \(n\) space-separated distinct integers \(a_1,a_2,\dots,a_n\), representing the coordinates of the factories.
  3. The third line contains \(n\) space-separated distinct integers \(b_1,b_2,\dots,b_n\), representing the coordinates of the mines.

You may assume that all coordinates lie within a reasonable range and are not equal to zero.

outputFormat

Output the sequence of operations, one per line. Each line should be either pickup(x) or offload(x), where x is the coordinate of the factory or mine visited in that operation.

The sequence must correspond to a valid set of operations that delivers all bombs from the factories to the mines with minimum total cost.

sample

1 1
5
10
pickup(5)

offload(10)

</p>