Baltic OI '09 - Beetle

View as PDF

Submit solution


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

Problem type

A beetle finds itself on a thin horizontal branch. "Here I am on a thin horizontal branch," thinks the beetle, "I feel pretty much like on an x-axis!" It surely is a beetle of deep mathematical thought.

There are also N drops of dew on that same branch, each holding M units of water. Their beetle–based integer coordinates are x_1, x_2,\dots , x_n. It is clear that the day will be hot. Already in one unit of time one unit of water goes away from each drop.

The beetle is thirsty. It is so thirsty that if it reached a drop of dew it would drink it in zero time. In one unit of time the beetle can crawl one unit of length.

But would all this crawling pay off? That's what buzzes the beetle. So you are to write a program which, given coordinates of dew drops, calculates the maximal amount of water the beetle can possibly drink.

Constraints

0\le N\le 300

1\le M\le 10^6

-10^4\le x_i\le 10^4

x_i\ne x_j when i\ne j

Input Specification

The input is read from standard input. The first line contains two integers N and M.

The next n lines contain integer coordinates x_1, x_2, \dots , x_n.

Output Specification

The program should write one line to standard output containing a single integer: the maximal amount of water the beetle can possibly drink.

Sample Input

3 15
6
-3
1

Sample Output

25

Sample Explanation

The beetle first goes to 1, starting at 0. 1 time unit passes, so when the beetle drinks, it gets 15-1=14 units of water.

The beetle then goes to -3 from 1. 4 more time units pass, so the beetle drinks 15-1-4=10 units of water.

The beetle goes to 6 from -3. 9 time units pass, so the beetle drinks 15-1-4-9=1 unit of water.

In total, the beetle drinks 25 units of water, which is the most it can drink.


Comments

There are no comments at the moment.