#P10712. [NOISG 2024 Prelim] Explosives

    ID: 12200 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2024Special JudgeNOISG(新加坡)

[NOISG 2024 Prelim] Explosives

Background

Translated from NOI SG 2024 Prelim E.Explosives

Problem Description

You are a truck driver transporting bombs.

There are nn factories (producing bombs) and nn mines (needing bombs) arranged on a straight line. The coordinate of the ii-th factory is aia_i, and the coordinate of the jj-th mine is bjb_j. Also, all aia_i and bjb_j are pairwise distinct.

Today, you need to pick up one bomb from each factory, and deliver each bomb to some mine. Initially, your position is 00. To complete this task, you may perform the following two operations:

  • pickup(x): Drive the truck from your current position to the factory located at xx. To perform this operation, the following two conditions must both hold:

    • There exists an ii such that x=aix=a_i
    • Your truck currently carries at most c1c-1 bombs.
  • offload(x): Drive the truck from your current position to the mine located at xx. To perform this operation, the following two conditions must both hold:

    • There exists a jj such that x=bjx=b_j
    • Your truck currently carries at least 11 bomb.

Because bombs are very dangerous, a safety officer must be on your truck. If you travel from point xx to point yy while the truck is carrying bombs, then you need to pay the safety officer xy|x-y| dollars. If the truck is carrying no bombs, then you do not need to pay any cost.

Find an operation sequence with the minimum total cost.

Input Format

The first line contains two integers n,cn,c

The second line contains nn integers, representing aa

The third line contains nn integers, representing bb

Output Format

The first line contains one integer, the minimum cost.

The second line outputs 2n2n integers, representing the coordinates of the factories and mines you visit, in the order you visit them.

For example, if you perform four operations: pickup(3), offload(5), pickup(6), offload(2), then you should output 3 5 6 2

3 2
12 14 4
9 5 8

7
4 5 14 12 9 8

Hint

Sample #1 Explanation

Visit factory 33, mine 22, factory 22, factory 11, mine 11, mine 33 in this order, and you can obtain the minimum value 77

In this sample, if you only output the correct minimum cost 77, you can get 50%50\% of the score for this testdata point.

Constraints

Subtask\text{Subtask} Score Special Property
00 Sample
11 1616 c=1c=1
22 2222 ai5000,bi>5000a_i\le 5000,b_i>5000
33 6262 None

For 100%100\% of the data, 1n,c1000,1ai,bi100001 \le n,c \le 1000,1 \le a_i,b_i \le 10000

Translated by ChatGPT 5