#P9000. [CEOI 2022] Measures

[CEOI 2022] Measures

Problem Description

There are NN people standing on a number line. Their initial positions are a1,a2,,aNa_1,a_2,\ldots,a_N, and they can move at a speed of 11 unit length per second.

For well-known reasons, they need to keep social distance, meaning that the distance between any two people must be at least DD.

Alenka designed an app to quickly compute the minimum time needed for these NN people to achieve social distancing by moving. Now she wants to add a new feature: support dynamically adding a person at position bib_i.

You need to implement a program to complete this feature.

Input Format

The first line contains three integers N,M,DN,M,D.

The next line contains NN integers a1,,aNa_1,\ldots,a_N, representing the initial NN people.

The next line contains MM integers b1,,bMb_1,\ldots,b_M, representing the MM people added one by one in order.

Output Format

Output one line with MM numbers. The ii-th number represents the minimum time required after adding the ii-th person. You must output the exact value of this time, without extra trailing 00.

2 1 2
1 3
2
1
0 5 3

1 2 3 4 5
0 1 2 3 4
3 3 3
3 3 3
3 3 3
4.5 6 7.5

Hint

Explanation for Sample 2

Constraints

For all testdata, 1D,a1,,aN,b1,,bM1091\le D,a_1,\ldots,a_N,b_1,\ldots,b_M\le 10^9.

Subtask ID Special Constraints Score
11 0N20000\le N\le 20001M101\le M\le 10 1010
22 0N2×1050\le N\le 2\times 10^51M101\le M\le 10 1414
33 N=0N=01M2×1051\le M\le 2\times 10^5b1bMb_1\le \cdots\le b_M 3535
44 N=0N=01M2×1051\le M\le 2\times 10^5 4141

Translated by ChatGPT 5