JDCC '17 Contest 1 S5 - Odd Treats

View as PDF

Submit solution

Points: 15
Time limit: 2.0s
Memory limit: 256M

Problem types

Vlad's favourite part of Halloween is giving out candy to trick or treaters. He has prepared a jar of M​ pieces of candy to give out to the N​ kids that will be visiting his home.

However, Vlad has noticed that the kids have devised a clever plan to get more candy from him this Halloween. The children will walk up to his house in order and if a child doesn't get at least \frac{5}{3} times more candy than the previous child, they will cry to their parents that Vlad is an evil vampire.

Vlad can't have the children ruining his reputation, however he also realizes that he won't have enough candy to please the kids. Instead, he decides that he'll "trick" some of the kids by taking their candy to refill his jar (every child has enough candy for him to refill his jar back to M​ candies). This will cause the child to cry to their parents and hurt his reputation, but hey it's called "trick or treat" for a reason. After tricking a child, Vlad can either treat the next child with one candy (restarting the \frac{5}{3} process), or also trick the next child.

Given the damage Vlad expects every child to cause to his reputation if he tricks them, can you figure out the minimum amount of damage that Vlad can cause to his reputation?

Input Specification

The first line of input contains two integers N, M \((1 \le N, ​M​ \le 100\) 000).

The next line contains N integers, where each integer C_i (1 \le C_i \le 10 000) represents the damage the i^{th} child would cause to Vlad's reputation if he tricked them.

Output Specification

The minimum amount of damage that Vlad can cause to his reputation.

Sample​ ​Input​ ​1

3 5
3 3 3

Sample​ ​Output​ ​1

3

Sample​ ​Input​ ​2

4 3
1 3 2 3

Sample​ ​Output​ ​2

2

Comments

There are no comments at the moment.