Activating Robots

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

요약
먼저 놓인 로봇들이 반시계 방향으로 계속 움직이는 원 위에서 활성화 지점에 도달해 R-1개의 로봇을 정확히 L/R 간격으로 배치하는 최소 시간을 구한다.
난이도

어려움10점 중 8점

유형
이분 탐색, 누적 합, 구현, 수학
정답자
아직 제출이 없습니다

문제

You and a single robot are initially at point 00 on a circle with perimeter LL (1≤L≤1091 \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 R−1R-1 robots such that at the end, every two consecutive robots are spaced L/RL/R away from each other (2≤R≤202\le R\le 20, RR divides LL). There are NN (1≤N≤1051\le N\le 10^5) activation points, the iith of which is located a_ia\_i distance counterclockwise from 00 (0≤a_i\<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 (1≤K≤1061\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 a_1,a_2,…,a_Na\_1,a\_2,\dots,a\_N.

출력

The minimum time required to achieve the goal.

예제4

  1. 예제 1

    입력
    10 2 1 2
    6
    
    예상 출력
    22
    
  2. 예제 2

    입력
    10 2 1 2
    7
    
    예상 출력
    4
    
  3. 예제 3

    입력
    32 4 5 2
    0 23 12 5 11
    
    예상 출력
    48
    
  4. 예제 4

    입력
    24 3 1 2
    16
    
    예상 출력
    48