#arc174a. A - A Multiply

A - A Multiply

Score: 300300 points

问题陈述

给定一个长度为 NN 的整数序列 A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N),以及一个整数 CC。 在执行以下操作 最多一次 后,找出 AA 中元素的最大可能和:

  • 指定整数 llrr,使得 1lrN1 \le l \le r \le N,并将 Al,Al+1,,ArA_l,A_{l+1},\dots,A_r 每个元素乘以 CC

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given an integer sequence of length NN, A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N), and an integer CC.
Find the maximum possible sum of the elements in AA after performing the following operation at most once:

  • Specify integers ll and rr such that 1lrN1 \le l \le r \le N, and multiply each of Al,Al+1,,ArA_l,A_{l+1},\dots,A_r by CC.

Constraints

  • All input values are integers.
  • 1N3×1051 \le N \le 3 \times 10^5
  • 106C106-10^6 \le C \le 10^6
  • 106Ai106-10^6 \le A_i \le 10^6

Input

The input is given from Standard Input in the following format:

NN CC

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer as an integer.

Sample Input 1

5 2
-10 10 20 30 -20

Sample Output 1

90

In this input, A=(10,10,20,30,20),C=2A=(-10,10,20,30,-20), C=2.
After performing the operation once specifying l=2l=2 and r=4r=4, AA will be (10,20,40,60,20)(-10,20,40,60,-20).
Here, the sum of the elements in AA is 9090, which is the maximum value achievable.

Sample Input 2

5 1000000
-1 -2 -3 -4 -5

Sample Output 2

-15

In this input, A=(1,2,3,4,5),C=1000000A=(-1,-2,-3,-4,-5), C=1000000.
Without performing the operation, the sum of the elements in AA is 15-15, which is the maximum value achievable.

Sample Input 3

9 -1
-9 9 -8 2 -4 4 -3 5 -3

Sample Output 3

13