Maximum Profit Window
Hard2s time · 256MB memory · arrays, dp
A trading desk may apply one boost to its daily results: choose at most one contiguous segment of days and multiply every value in it by X. (Choosing no segment is allowed.)
Find the maximum possible total sum of the array after the boost.
Input
The first line contains two integers n and X.
The second line contains n integers a₁ … aₙ.
Output
Print the maximum possible total.
Constraints
- 1 ≤ n ≤ 2·10⁴
- −10⁷ ≤ aᵢ ≤ 10⁷
- 1 ≤ X ≤ 10⁵
- The answer can be far outside 32-bit range — use 64-bit integers.
Samples
Input 1
5 3 1 -2 4 -1 3
Output 1
17
Input 2
3 5 -1 -2 -3
Output 2
-6
Sign in (top right) to run or submit.