QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#8541. Activating Robots

統計

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

Your goal is to place exactly $R-1$ robots such that at the end, every two consecutive robots are spaced $L/R$ away from each other ($2\le R\le 20$, $R$ divides $L$). There are $N$ ($1\le N\le 10^5$) activation points, the $i$th of which is located $a_i$ distance counterclockwise from $0$ ($0\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 $1$ unit per $K$ seconds ($1\leq K\leq 10^6$).

Compute the minimum time required to achieve the goal.

Input

The first line contains $L$, $R$, $N$, and $K$.

The next line contains $N$ space-separated integers $a_1,a_2,\dots,a_N$.

Output

The minimum time required to achieve the goal.

Examples

Input

10 2 1 2
6

Output

22

We can reach the activation point at $6$ in $4$ seconds by going clockwise. At this time, the initial robot will be located at $2$. Wait an additional $18$ seconds until the initial robot is located at $1$. Now we can place a robot to immediately win.

Input

10 2 1 2
7

Output

4

We can reach the activation point at $7$ in $3$ seconds by going clockwise. At this time, the initial robot will be located at $1.5$. Wait an additional second until the initial robot is located at $2$. Now we can place a robot to immediately win.

Input

32 4 5 2
0 23 12 5 11

Output

48

Input

24 3 1 2
16

Output

48

Scoring

  • Inputs 5-6: $R=2$
  • Inputs 7-12: $R\le 10, N\le 80$
  • Inputs 13-20: $R\le 16$
  • Inputs 21-24: No additional constraints.

Problem credits: Benjamin Qi

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.