C - Blue Spring Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

高橋君は NN 日間の鉄道旅行を計画しています。
高橋君はそれぞれの日について、運賃の通常料金を払うか、11 日周遊パスを 11 枚使用するか選ぶことができます。

ここで、1iN1\leq i\leq N について、ii 日目の旅行にかかる運賃の通常料金は FiF_i 円です。
一方、11 日周遊パスは DD 枚セットで PP 円で発売されており、何セットでも購入することが可能ですが、DD 枚単位でしか購入することができません。
また、購入したパスは 11 枚ずつ好きな日に使うことができ、旅行が終了した時点で余っていても構いません。

NN 日間の旅行でかかる金額、すなわち 11 日周遊パスの購入にかかった代金と、11 日周遊パスを利用しなかった日における運賃の通常料金の合計金額の和としてあり得る最小値を求めてください。

制約

  • 1N2×1051\leq N\leq 2\times 10^5
  • 1D2×1051\leq D\leq 2\times 10^5
  • 1P1091\leq P\leq 10^9
  • 1Fi1091\leq F_i\leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN DD PP
F1F_1 F2F_2 \ldots FNF_N

出力

NN 日間の旅行でかかる金額としてあり得る最小値を出力せよ。


入力例 1Copy

Copy
5 2 10
7 1 6 3 6

出力例 1Copy

Copy
20

11 日周遊パスを 11 セットだけ購入し、11 日目と 33 日目に使用すると、合計金額は (10×1)+(0+1+0+3+6)=20(10\times 1)+(0+1+0+3+6)=20 となり、このときかかる金額が最小となります。
よって、2020 を出力します。


入力例 2Copy

Copy
3 1 10
1 2 3

出力例 2Copy

Copy
6

33 日間すべてにおいて運賃の通常料金を支払ったときに最小となります。


入力例 3Copy

Copy
8 3 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

出力例 3Copy

Copy
3000000000

11 日周遊パスを 33 セット購入し、88 日間すべてにおいて 11 日周遊パスを利用したときに最小となります。
答えが 3232 bit 整数型に収まらないことがあることに注意してください。

Score : 300300 points

Problem Statement

Takahashi is planning an NN-day train trip.
For each day, he can pay the regular fare or use a one-day pass.

Here, for 1iN1\leq i\leq N, the regular fare for the ii-th day of the trip is FiF_i yen.
On the other hand, a batch of DD one-day passes is sold for PP yen. You can buy as many passes as you want, but only in units of DD.
Each purchased pass can be used on any day, and it is fine to have some leftovers at the end of the trip.

Find the minimum possible total cost for the NN-day trip, that is, the cost of purchasing one-day passes plus the total regular fare for the days not covered by one-day passes.

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • 1D2×1051\leq D\leq 2\times 10^5
  • 1P1091\leq P\leq 10^9
  • 1Fi1091\leq F_i\leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN DD PP
F1F_1 F2F_2 \ldots FNF_N

Output

Print the minimum possible total cost for the NN-day trip.


Sample Input 1Copy

Copy
5 2 10
7 1 6 3 6

Sample Output 1Copy

Copy
20

If he buys just one batch of one-day passes and uses them for the first and third days, the total cost will be (10×1)+(0+1+0+3+6)=20(10\times 1)+(0+1+0+3+6)=20, which is the minimum cost needed.
Thus, print 2020.


Sample Input 2Copy

Copy
3 1 10
1 2 3

Sample Output 2Copy

Copy
6

The minimum cost is achieved by paying the regular fare for all three days.


Sample Input 3Copy

Copy
8 3 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3Copy

Copy
3000000000

The minimum cost is achieved by buying three batches of one-day passes and using them for all eight days.
Note that the answer may not fit into a 3232-bit integer type.



2025-04-28 (Mon)
14:29:50 +00:00