PivotOJ

Activating Robots

시간 제한: 5000ms메모리 제한: 1024MB출처: USACO 2024 Open PlatinumBOJ 31765

문제

You and a single robot are initially at point 00 on a circle with perimeter LL (1L1091 \le L \le 10^9). You can move either counterclockwise or clockwise along the circle at 11 unit per second. All movement in this problem is continuous.

Your goal is to place exactly R1R-1 robots such that at the end, every two consecutive robots are spaced L/RL/R away from each other (2R202\le R\le 20, RR divides LL). There are NN (1N1051\le N\le 10^5) activation points, the iith of which is located aia_i distance counterclockwise from 00 (0ai<L0\le a_i<L). If you are currently at an activation point, you can instantaneously place a robot at that point. All robots (including the original) move counterclockwise at a rate of 11 unit per KK seconds (1K1061\leq K\leq 10^6).

Compute the minimum time required to achieve the goal.

입력

The first line contains LL, RR, NN, and KK.

The next line contains NN space-separated integers a1,a2,,aNa_1,a_2,\dots,a_N.

출력

The minimum time required to achieve the goal.

예제

예제 1

입력
10 2 1 2
6
출력
22

예제 2

입력
10 2 1 2
7
출력
4

예제 3

입력
32 4 5 2
0 23 12 5 11
출력
48

예제 4

입력
24 3 1 2
16
출력
48
코드를 제출하려면 로그인하세요.