아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Watching Mooloo

면접 대비

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

요약
시청하는 날짜들과 구독료 K와 기간 d의 합으로 결정되는 비용 구조에서 모든 날짜를 채우는 최소 비용을 구한다.
난이도

보통10점 중 4점

유형
그리디, 수학
정답자
아직 제출이 없습니다

문제

Bessie likes to watch shows on Mooloo. Because Bessie is a busy cow, she has planned a schedule for the next NN (1≤N≤1051 \leq N \leq 10^5) days that she will watch Mooloo. Because Mooloo is a paid subscription service, she now needs to decide how to minimize the amount of money she needs to pay.

Mooloo has an interesting subscription system: it costs d+Kd + K (1≤K≤1091\le K\le 10^9) moonies to subscribe to Mooloo for dd consecutive days. You can start a subscription at any time, and you can start a new subscription as many times as you desire if your current subscription expires. Given this, figure out the minimum amount of moonies Bessie needs to pay to fulfill her schedule.

입력

The first line contains integers NN and KK.

The second line contains NN integers describing the days Bessie will watch Mooloo: 1≤d_1\<d_2<…\<d_N≤10141\le d\_1\<d\_2<\dots\<d\_N\le 10^{14}.

출력

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

예제2

  1. 예제 1

    입력
    2 4
    7 9
    
    예상 출력
    7
    
  2. 예제 2

    입력
    2 3
    1 10
    
    예상 출력
    8