#abc267c. C - Index × A(Continuous ver.)

C - Index × A(Continuous ver.)

Score : 300300 points

问题描述

给定一个长度为 NN 的整数序列 A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N)

求出该序列中长度为 MM 的连续子数组 B=(B1,B2,,BM)B=(B_1,B_2,\dots,B_M),使得 i=1Mi×Bi\displaystyle \sum_{i=1}^{M} i \times B_i 的最大值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given an integer sequence A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N) of length NN.

Find the maximum value of i=1Mi×Bi\displaystyle \sum_{i=1}^{M} i \times B_i for a contiguous subarray B=(B1,B2,,BM)B=(B_1,B_2,\dots,B_M) of AA of length MM.

Notes

A contiguous subarray of a number sequence is a sequence that is obtained by removing 00 or more initial terms and 00 or more final terms from the original number sequence.

For example, (2,3)(2, 3) and (1,2,3)(1, 2, 3) are contiguous subarrays of (1,2,3,4)(1, 2, 3, 4), but (1,3)(1, 3) and (3,2,1)(3,2,1) are not contiguous subarrays of (1,2,3,4)(1, 2, 3, 4).

Constraints

  • 1MN2×1051 \le M \le N \le 2 \times 10^5
  • 2×105Ai2×105- 2 \times 10^5 \le A_i \le 2 \times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.

Sample Input 1

4 2
5 4 -1 8

Sample Output 1

15

When B=(A3,A4)B=(A_3,A_4), we have $\displaystyle \sum_{i=1}^{M} i \times B_i = 1 \times (-1) + 2 \times 8 = 15$. Since it is impossible to achieve 1616 or a larger value, the solution is 1515.

Note that you are not allowed to choose, for instance, B=(A1,A4)B=(A_1,A_4).

Sample Input 2

10 4
-3 1 -4 1 -5 9 -2 6 -5 3

Sample Output 2

31

update @ 2024/3/10 11:16:28