PivotOJ

Tycho

시간 제한: 2000ms메모리 제한: 1024MB출처: BOI 2023BOJ 31976

문제

The planetary exploration vehicle Tycho VIII needs to get back to the home base after collecting mineral samples. Tycho travels in a straight line from position 00 to the home base at position bb. While moving, it advances at a slow but steady pace of 11 unit per second. Every second, Tycho takes 11 unit of environmental damage from the harsh planetary conditions.

The situation is made even worse by radiation from a nearby pulsar, which adds dd additional units of damage every pp seconds. However, the radiation damage can be avoided by seeking shelter in one of nn different hiding spots---caves, vegetation, large rocks, carcasses of the planet's megafauna---along the way. Tycho can choose to stand still at any point for any integer number of seconds.

The starting position 00 and the home base at bb are both sheltered, so Tycho takes no radiation damage there.

What is the minumum damage Tycho will take on its journey back to the home base?

Consider the situation where the home base is at position 1818 and there are shelters at positions 88 and 1515.

Assume that the pulsar's period is 44, so unsheltered Tycho would take damage at times 44, 88, 1212, etc. If Tycho leaves from the starting position (where it's sheltered) at time 00, it can reach the first shelter after 88 seconds, incurring radiation damage dd at time 44 (but none at time 88 because it's sheltered then). Continuing without stopping, it reaches the home base at time 1818, incurring d+dd+d more units of radiation damage (at times 1212 and 1616, respectively). This way it incurs d+d+d=3dd+d+d=3d units of radiation damage and 1818 units of environmental damage. If instead Tycho waits at the 22nd shelter (at position 1515) for 11 second, the pulse at time 1616 causes it no damage, and it reaches the home base at time 1919 with a total of 2d+192d + 19 units of damage. This is better for most values of dd. The two situations are shown here:

If the pulsar's period is 1010, Tycho can wait at the starting position for 22 seconds and then just go home without stopping at any shelter. Thus it passes the 11st shelter (at position 88) at just the right moment when the pulsar flares and arrives at the home base at time 2020, for a total of 2020 environmental damage and no radiation damage at all.

입력

The first line consists of four integers bb, pp, dd, and nn, separated by single spaces: the location bb of the home base, the pulsar's flare period pp, the additional radiation damage dd caused by each flare of the pulsar, the number nn of the shelters. The following nn lines each contain an integer giving the shelter locations a1a_1, \ldots, ana_n, with 0<a1<<an<b0<a_1<\cdots <a_n< b.

출력

Print a single integer: the minimum amount of damage Tycho must take to reach bb.

예제

예제 1

입력
18 4 5 2
8
15
출력
29

예제 2

입력
18 4 0 2
8
15
출력
18

예제 3

입력
18 10 100 2
8
15
출력
20

예제 4

입력
18 4 100 0
출력
418

예제 5

입력
65 20 100 3
14
25
33
출력
172
코드를 제출하려면 로그인하세요.