PDP-23 (2011) - Phase C' - 2 (Fishboats)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python
Fishboats

On a beach with a straight-line shape, there is a fish tavern located at coordinate zero. To the right and left of the fish tavern (in positive and negative coordinates), N fishing boats (fishboats) arrive every morning, each bringing M kilograms of fish to sell. The tavern owner, knowing that he will have many customers in the evening, wants to buy as many kilograms of fish as possible. Thus, he starts from the tavern exactly when the fishing boats dock on the beach (all simultaneously) and covers a distance of one unit in the unit of time. Each time he reaches a fishing boat, the tavern owner purchases the amount of fish it offers and immediately moves on to the next fishing boat (without any time interval). However, during each unit of time until the tavern owner arrives, each fishing boat sells one kilogram of fish to tourists strolling on the beach. The task is to find the maximum number of kilograms of fish that the tavern owner can buy.

Input Files

The first line of input will contain exactly two positive integers separated by a single space: the values of N and M. The second line will contain N non-zero integers X_1, ..., X_N separated by spaces: the coordinates of the points on the beach where the fishing boats arrive.

Output Files

The output should consist of a single line containing exactly one integer: the maximum number of kilograms of fish the tavern owner can buy.

Example of Input - Output Files:

STDIN (phishboats.in)

3 20
8
-2
1

STDOUT (phisboats.out)

41
Constraints
  • 1 \le N \le 300
  • 1 \le M \le 1.000.000
  • -10.000 \le X_i \le 10.000
  • Τime limit: 1 sec.

Comments

There are no comments at the moment.