#P11142. [APC001] Ex - Separation

[APC001] Ex - Separation

Problem Description

Xiao I has nn factories located along the route from place AA to place BB. The distance from AA to the ii-th factory is aia_i kilometers. The processing plant is at place BB, which is xx kilometers away from AA. Xiao I needs to transport the goods from these factories to the processing plant at BB.

However, there was a heavy rainstorm today, and the goods in the warehouses got damp. For each item of goods, for every 11 minute it is stored in a warehouse or in Xiao I's backpack, its value decreases by mm yuan. It is known that tonight each factory will produce bib_i items of goods, and it is also known how many minutes after the rainstorm begins each item will be produced.

Xiao I's initial stamina is cc, and his speed is 11 kilometer per minute. But every time he walks 11 kilometer, he loses 11 stamina point (when stamina is 00, walking is not allowed). Each time he sets out, Xiao I must go from AA to BB, and then return from BB to AA. He only takes away all goods that have been produced in the warehouses of the factories along the way when traveling from AA to BB. After he arrives at AA, he can immediately set out again. In particular, he may set out at a negative time. Assume his backpack has infinite capacity, and the weight of goods does not affect stamina consumption.

To reduce the loss, Xiao I built a clone-making device. This machine can create infinitely many clones of him, but for each departure, at most one clone can be created. The clones share stamina with the original body, and strictly follow the operations described in Paragraph 3. Xiao I must ensure that at any time, the current stamina can support every existing clone (including the original) to return home at AA.

After finishing preparations, Xiao I finds that the rainstorm has already lasted for kk minutes. He urgently wants to know the minimum amount of money he will lose (i.e., the decrease in value of the goods), and he asks you for help to provide a plan.

Input Format

This problem has multiple sets of testdata within a single test point.

The first line contains an integer tt, the number of test cases.

Then, for each test case:

The first line contains five integers n,m,x,c,kn,m,x,c,k.

The next line contains nn integers a1ana_1\sim a_n.

The next line contains nn integers b1bnb_1\sim b_n.

The next nn lines: the ii-th line contains bib_i integers, indicating that the goods in factory ii are produced ti,jt_{i,j} minutes after the rainstorm begins.

Output Format

For each test case:

If it is impossible for Xiao I to transport all goods to the processing plant and return home, output a single line containing -1.

Otherwise, output an integer on the first line, the minimum amount of money Xiao I will lose.

Then output several lines, each line containing two numbers. For the ii-th such line:

  • The first number is the departure time of Xiao I's ii-th trip (measured from when he asked you for help). It must be output in increasing order, and the time may be negative.

  • The second number indicates whether a new clone needs to be created for this trip. If yes, output 11, otherwise output 00.

If a solution exists, after finishing the output of the plan, output a line -1 -1 to indicate the end of the plan.

1
1 2 2 5 1
1
2
3 4
6
2 0
-1 -1
1
1 1 1 5 1
1
2
3 4
0
1 0
2 1
-1 -1
4
1 1 2 5 1
1
2
3 4
1 1 4 8 2
1
2
5 8
2 2 3 9 9
1 2
2 1
3 7
5
1 1 2 8 4
1
3
1 2 3
3
2 0
-1 -1
9
5 0
-1 -1
24
-3 0
-1 -1
4
-3 0
-2 1
-1 -1

Hint

[Sample Explanation]

For the first test case of sample 33:

Xiao I asks you for help 11 minute after the rainstorm begins. The plan you provide is: at 33 minutes after the rainstorm begins, Xiao I leaves home, reaches warehouse 11 at 44 minutes, reaches place BB at 55 minutes, returns home at 77 minutes, and the loss is 33 yuan.

[Constraints]

For all testdata, it is guaranteed that 1t101\leq t\leq 10,1n2×105,1m,k,x1061\leq n\leq 2\times 10^5,1\leq m,k,x\leq 10^6, 1aix1\le a_i\le x, 0c2000\leq c\leq 200, 1bi1051\leq b_i\leq 10^5, bi2×105\sum b_i\leq 2\times 10^5, 0ti,j1060\leq t_{i,j}\leq 10^6.

The input size of this problem is large. Please use a fast input method.

The statement of this problem has been updated. Original statement during the contest.

Translated by ChatGPT 5