Heroes

Time limit: 0.35s Memory limit: 256MB Input: Output:

— Billy, you are wasting your life on computer games!
— That's OK, Mom, I have three lives left!

In the Great Battle to save everything good in this world, HH heroes are fighting a horde of MM monsters. The combatants are standing in a circle, in a given order. The ii-th hero is followed on the circle by mim_i monsters (such that m1+m2++mH=Mm_1 + m_2 + \dots + m_H = M).

Beginning with the first hero, combatants take turns striking with their swords. A hero may strike any monster, while a monster may strike any hero (anywhere on the circle). A monster that takes KK strikes is destroyed. Heroes are invincible.

Task

The heroes are fighting for glory and wish to receive as few strikes as possible. What is the least number of strikes that the heroes must receive before destroying all the monsters?

Input data

The first line of input will contain the integers HH and KK, separated by a space.

The second line will contain HH space-separated integers, m1m_1, m2m_2, ..., mHm_H.

Output data

Output a single integer, the minimum number of strikes that the heroes can receive.

Constraints and clarifications

  • 1H3 0001 \leq H \leq 3 \ 000
  • 1M1 000 000 0001 \leq M \leq 1 \ 000 \ 000 \ 000
  • 1K1 0001 \leq K \leq 1 \ 000
  • 0miM0 \leq m_i \leq M for 1iH1 \leq i \leq H
  • The answer is guaranteed not to exceed 101810^{18}.
# Points Constraints
0 0 Examples
1 7 H10H \leq 10, M4M \leq 4, K4K \leq 4
2 11 H20H \leq 20, M10M \leq 10, K30K \leq 30
3 15 M150 000M \leq 150 \ 000
4 17 M5 000 000M \leq 5 \ 000 \ 000
5 19 M30 000 000M \leq 30 \ 000 \ 000
6 31 No additional constraints

Example 1

stdin

3 1
0 3 3

stdout

3

Explanation

There are H=3H=3 heroes and M=6M=6 monsters with K=1K=1 life each. The initial order is HHMMMHMMM (where H is a hero and M is a monster). The first two heroes destroy the first two monsters. The third monster strikes. The third hero destroys the fourth monster. The last two monsters strike. The circle is now HHMHMM. The second time around, every hero destroys one monster and the heroes receive no further strikes.

Example 2

stdin

3 2
0 3 3

stdout

10

Log in or sign up to be able to send submissions!