Tycho

시간 제한2초메모리 제한1024 MB

요약
쉴터에서 언제 얼마나 머물지 정해, 이동 중 펄서의 섬광에 노출되지 않게 하면서 이동 시간과 방사선 피해의 합을 최소화한다.
난이도

보통10점 중 7점

유형
동적 계획법, 정수론, 수학
정답자
아직 제출이 없습니다

문제

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 a_1a\_1, …\ldots, a_na\_n, with 0\<a_1<⋯\<a_n<b0\<a\_1<\cdots \<a\_n< b.

출력

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

제한

You can assume p<bp < b and n<bn < b. We always have 1≤b≤10121\leq b\leq 10^{12}, 0≤d≤1060\leq d \leq 10^6, and 0≤n≤1050\leq n \leq 10^5.

예제5

  1. 예제 1

    입력
    18 4 5 2
    8
    15
    
    예상 출력
    29
    
  2. 예제 2

    입력
    18 4 0 2
    8
    15
    
    예상 출력
    18
    
  3. 예제 3

    입력
    18 10 100 2
    8
    15
    
    예상 출력
    20
    
  4. 예제 4

    입력
    18 4 100 0
    
    예상 출력
    418
    
  5. 예제 5

    입력
    65 20 100 3
    14
    25
    33
    
    예상 출력
    172