创建于 2026/07/18 · 更新于 2026/07/18
You are given the coordinates of defense machines and 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 per machine (they can also be controlled to shoot in either direction).
A laser has a maximum range of . 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 , 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 with cost).
Find the minimum total cost required to eliminate all monsters.
The first line contains four integers , , , and — 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 integers — the coordinates of the pre-existing machines. The third line contains integers — the coordinates of the monsters.
All input values are positive integers.
Output a single integer — the minimum total cost to eliminate all monsters.
2 6 4 5
7 21
1 2 10 14 18 23
18
2 3 1 10
1 9
3 5 7
3