Linear Ether Geometry
Time limit8sMemory limit512 MB
Connect N libraries on a hallway to the internet using M cables and hubs, minimizing hubs first then total cable slack.
- Level
Medium7 of 10
- Topics
- Greedy, Backtracking, Graph
- Solved
- No attempts yet
Problem
Euclid, who lived in Alexandria, decided to buy a new house and move, because his study had become cramped with all the books he had bought.
The new house has many libraries. His first task is to connect every library to the Internet. As shown in Figure 3, all the libraries are located along one side of a straight hallway, and each library has a connector to its inside on the wall (shown as ◦ in the figure). He has already finished the wiring inside each library, so next he has to connect the libraries to the Internet. The only connector to the Internet is at the end of the hallway (shown as • in the figure).

Figure 3: The hallway and the libraries
He brought several Ethernet cables and plenty of hubs with enough ports from his old house. He wants to connect all libraries to the Internet with them. He also wants to lay the cables straight along the wall, as illustrated in Figure 4. His first goal is to minimize the number of hubs used, and his second goal is to minimize the slack of the cables, that is, the total extra length of the cables.

Figure 4: Laying cables along the wall
Model the hallway as the segment of a number line. The Internet connector is at , and the connector of the -th library is at . The wiring rules are as follows.
- A cable joins two points, each of which is a connector or a hub. If the two points are at distance and the cable has length , then must hold, and the extra length of this cable is .
- The Internet connector and each library connector take exactly one cable. Cables can be joined to each other only at a hub.
- A hub has as many ports as needed and can be placed at any position inside the hallway (a coordinate from to inclusive). Several hubs may share a position, and cables may overlap.
- Not every cable has to be used, but each cable can be used at most once.
- Every library connector must be connected to the Internet connector through cables and hubs.
For each given situation, find the minimum number of hubs, and the minimum total extra length of the cables among layouts that use that many hubs. You may assume that the sizes of hubs and the thicknesses of cables are negligible.
Input
The input consists of multiple datasets. Each dataset has the following format.
N M L
x1 x2 ... xN
l1 l2 ... lM
The first line contains three integers , , and , where () is the number of libraries, () is the number of cables, and () is the length of the hallway. The second line contains positive integers in increasing order. The -th integer is the x-coordinate of the connector of the -th library, and . The third line contains positive integers in non-decreasing order. The -th integer is the length of the -th cable. No cable is longer than .
The input ends with a line containing three zeros. This line is not a dataset.
Output
For each dataset, print two integers on one line, separated by a single space. The first integer is the minimum number of hubs, and the second is the minimum total extra length of the cables.
If no layout is possible, print Impossible instead.