Baltic OI '09 P1 - Beetle

View as PDF

Submit solution


Points: 10
Time limit: 1.0s
Memory limit: 512M

Problem type
Baltic Olympiad in Informatics: 2009 Day 1, Problem 1

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, ... ,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.

Input Specification

The first line of input contains two integers n and m. The next n lines contain the integer coordinates x_1, x_2, ... ,x_n.

Output Specification

One line containing a single integer: the maximal amount of water the beetle can possibly drink.

Sample Input

3 15
6
-3
1

Sample Output

25

Constraints

0 \le n \le 300

1 \le m \le 1 \: 000 \: 000

-10 \: 000 \le x_1, x_2, ... ,x_n \le 10 \: 000

x_i \neq x_j for i \neq j


Comments


  • 3
    Nils_Emmenegger  commented on Nov. 27, 2021, 4:32 p.m.

    It is possible for x_i to equal 0, in which case the beetle has already drunk m units of water after 0 units of time have passed. I was a bit confused by this, so I figured I'd mention it here in case it helps someone out in the future.