题目收集
题目列表题单
返回列表

Shooting Game

CodeforcesP0075· 2000ms· 1024 MB· ZJU Summer 2026 Contest 7原题链接
dp数据结构优化

创建于 2026/07/18 · 更新于 2026/07/18

题目描述

You are given the coordinates of MMM defense machines and EEE monsters on a 1D coordinate axis.

To eliminate all monsters, you can control each machine to shoot a laser to the left, shoot a laser to the right, or remain turned off. You can also build new machines at any integer coordinate for a fixed cost of CCC per machine (they can also be controlled to shoot in either direction).

A laser has a maximum range of LLL. It pierces through and eliminates all monsters in its path, including both endpoints. You can control the length of the laser, but it cannot exceed LLL, nor can it pass through another machine, whether it is turned on or off.

The energy cost of firing a laser is equal to the laser's length. (Note: If a monster is located exactly at a machine's coordinate, you can eliminate it by shooting a lazer in either direction at any length, including length 000 with 000 cost).

Find the minimum total cost required to eliminate all monsters.

输入格式

The first line contains four integers MMM, EEE, CCC, and LLL — the number of pre-existing machines, the number of monsters, the fixed cost to build a new machine, and the maximum range of a laser.

The second line contains MMM integers m1,m2,…,mMm_1, m_2, \dots, m_Mm1​,m2​,…,mM​ — the coordinates of the pre-existing machines. The third line contains EEE integers e1,e2,…,eEe_1, e_2, \dots, e_Ee1​,e2​,…,eE​ — the coordinates of the monsters.

Constraints:

1≤M,E≤1061 \le M, E \le 10^61≤M,E≤106

1≤C,L≤1091 \le C, L \le 10^91≤C,L≤109

1≤m1<m2<⋯<mM≤1091 \le m_1 \lt m_2 \lt \dots \lt m_M \le 10^91≤m1​<m2​<⋯<mM​≤109

1≤e1<e2<⋯<eE≤1091 \le e_1 \lt e_2 \lt \dots \lt e_E \le 10^91≤e1​<e2​<⋯<eE​≤109

All input values are positive integers.

输出格式

Output a single integer — the minimum total cost to eliminate all monsters.

样例输入 #1

2 6 4 5
7 21
1 2 10 14 18 23

样例输出 #1

18

样例输入 #2

2 3 1 10
1 9
3 5 7

样例输出 #2

3