Police Investigation

Time limit: 0.4s Memory limit: 64MB Input: Output:

Fearsome William is still free, and the Police is searching him in Murder Boulevard!

This street is LL meters long, and currently William is at x=0x=0, trying to reach his nest at x=Lx=L.

Along this street there are NN semaphores at positions XiX_i.

All the traffic lights are synchronized: at t=0t=0 the green triggers, and will stay green for TT seconds; at t=Tt=T the red triggers, and will stay red for TT seconds; and then the cycle repeats.

William wants to reach his nest as quickly as possible, but he doesn't want to attract too much attention.

Therefore, he travels at a constant speed of 11 meter per second (the speed limit), and he will stop and wait if he's at a red semaphore.

Since he's very impatient, sometimes he may cross the red semaphore without waiting for the green, but he can do so at most RR times.

Which is the least amount of time William needs to reach his nest?

Input data

The first line of the input contains 4 integers: NN (the number of semaphores), RR (the number of semaphores William can skip), TT (the half-period of the semaphores), and LL (the length of the street).

The second line contains NN integers: the coordinates XiX_i.

Output data

The output contains a single line with an integer: the minimum time in seconds that will be needed to reach the nest.

Constraints and clarifications

  • 1RN10 0001 \leq R \leq N \leq 10 \ 000
  • 1T1 0001 \leq T \leq 1 \ 000
  • N<L109N < L \leq 10^9
  • Xi<LX_i < L, for each semaphore
  • Xi<Xi+1X_i < X_{i+1} for each ii from 00 to n2n-2
  • For tests worth 10 points, N=1N = 1.
  • For tests worth 15 more points, R=0R = 0.
  • For tests worth 15 more points, N20N \leq 20 and L1 000L \leq 1 \ 000.
  • For tests worth 25 more points, N,T100N, T \leq 100 and L1 000L \leq 1 \ 000.
  • For tests worth 15 more points, N300N \leq 300.

Example 1

stdin

3 1 3 10
1 5 9

stdout

11

Explanation

In the first sample case there are 3 semaphores, of which 1 can be skipped. When William reaches the first semaphore he finds it green, so it will pass.

Then at t=5t=5 he reaches the second semaphore (at x=5x=5), but it is red (since t=3t=3).
He has two choices: wait 1 second that it becomes green, or skip the semaphore.

If he waits, he will start again at t=6t=6, will reach the last semaphore (at t=10t=10) and will skip it since it is red and he still has 11 skip remaining. He reaches his nest at t=11t=11.

If he skips it, he will reach the last semaphore at t=9t=9, but it is red (it just became red). There he has to wait 3 seconds that it becomes green again, leaving it at t=12t=12. He reaches his nest at t=13t=13.

Therefore, the best solution is to wait at the second semaphore and skip the last one, reaching the nest in 11 seconds.

Example 2

stdin

1 0 5 10
5

stdout

15

Explanation

In the second sample case there is only one semaphore.

When William reaches it he finds it red (it just became red), and he will wait since he doesn't have any skip available.

Log in or sign up to be able to send submissions!