#K77237. Maximum Product of Selected Elements

    ID: 34820 Type: Default 1000ms 256MiB

Maximum Product of Selected Elements

Maximum Product of Selected Elements

You are given a sequence of integers \(b_1, b_2, \ldots, b_N\). Your task is to select exactly \(M\) elements from this sequence (while preserving their original order) such that the product of the chosen elements is maximized. Formally, if you select indices \(1 \leq i_1 < i_2 < \cdots < i_M \leq N\), then you must maximize the product \(b_{i_1} \times b_{i_2} \times \cdots \times b_{i_M}\).

Note: The input guarantees that \(N\) and \(M\) are small (e.g., \(N \leq 10\)), so a brute force approach that examines every combination is acceptable.

inputFormat

The first line of input contains two space-separated integers \(N\) and \(M\), where \(N\) is the length of the sequence and \(M\) is the number of elements to select.

The second line contains \(N\) space-separated integers representing the sequence \(b_1, b_2, \ldots, b_N\).

outputFormat

Output a single integer which is the maximum product that can be achieved by selecting exactly \(M\) elements from the sequence while preserving their order.

## sample
5 3
1 2 3 4 5
60

</p>