#P4530. Maximizing Basketball Course Score

    ID: 17776 Type: Default 1000ms 256MiB

Maximizing Basketball Course Score

Maximizing Basketball Course Score

In a university sports class, there are n basketballs (with n \ge m) each having an integer written on it (not necessarily distinct, and its absolute value is less than 10000). There are m baskets, each equipped with a scoring display that initially shows 1.

During the test, a student must make exactly n shots by throwing each basketball exactly once into one of the baskets, with the restriction that every basket must be hit at least once. When a basketball with number x is thrown into a basket whose display currently shows y, the display updates to y \times x.

The raw score S is defined as the sum of the final values on all m baskets, i.e., \[ S = \sum_{i=1}^{m} (\text{product of numbers assigned to basket } i) \] A larger S means a higher final grade.

King, a star shooter, is guaranteed to make all shots but is unsure how to assign his n basketballs into m baskets to maximize his raw score S. Can you help him find the best strategy?

inputFormat

The input consists of two lines:

  • The first line contains two integers n and m where n is the number of basketballs and m is the number of baskets (n \ge m).
  • The second line contains n integers representing the numbers written on the basketballs.

You can assume that the absolute value of each number is less than 10000.

outputFormat

Output a single integer which is the maximum possible raw score S King can achieve by optimally assigning the basketballs to the baskets.

sample

3 2
2 3 -1
5