問題一覧 > 通常問題

No.3050 Prefix Removal

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 52
作問者 : suisen / テスター : 37zigen 👑 rin204
お気に入りにしたユーザー ProblemId : 9025 / 自分の提出
問題文最終更新日: 2025-02-08 13:48:15
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 459 (順位表) の他の問題:

Problem Statement

You are given positive integers $N, K$ and an integer sequence $A = (A _ 1, A _ 2, \ldots, A _ N)$ of length $N$.

Suisen's current satisfaction is $0$. He will now perform the following for $i = 1, 2, \ldots, K$, in this order.

  • Let $\vert A\vert$ be the length of the sequence $A$.
    • If $\vert A\vert = 0$: Suisen's satisfaction becomes $-10 ^ {100}$.

    • If $\vert A\vert \geq 1$: choose an integer $p$ satisfying $1\leq p\leq \vert A\vert$ and remove the first $p$ elements of $A$. Letting $S$ be the sum of the elements removed, Suisen's satisfaction increases by $S\times i$.

      For example, if $p=2$ is chosen for $A=(-3,2,1)$, the first $2$ elements $-3,2$ are removed, resulting in $A = (1)$. The sum of the elements removed is $(-3)+2=-1$, so Suisen's satisfaction increases by $(-1)\times i$.

Find the maximum possible value of Suisen's satisfaction after all the operations are finished.

Input

$N\ K$
$A _ 1\ A _ 2 \ \cdots \ A _ N$
  • All input values are integers.
  • $1\leq K \leq N\leq 5\times 10 ^ 5$
  • $\vert A _ i \vert \leq 10 ^ 7$

Output

Print the answer on $1$ line. End the output with a newline.

Sample

Sample 1
Input
5 3
3 2 0 1 -1
Output
10

Here, $N = 5, K = 3, A = (3,2,0,1,-1)$. By performing the operations as follows, the final satisfaction becomes $10$.

  • $i = 1$: We have $A = (3,2,0,1,-1)$, and the length of the sequence $A$ is $5$. Choosing $p=1$ removes the first $1$ element $3$, resulting in $A = (2,0,1,-1)$. The sum of the elements removed is $3$, so $3 \times 1 = 3$ is added to the satisfaction, making it $3$.
  • $i = 2$: We have $A = (2,0,1,-1)$, and the length of the sequence $A$ is $4$. Choosing $p=1$ removes the first $1$ element $2$, resulting in $A = (0,1,-1)$. The sum of the elements removed is $2$, so $2 \times 2 = 4$ is added to the satisfaction, making it $7$.
  • $i = 3$: We have $A = (0,1,-1)$, and the length of the sequence $A$ is $3$. Choosing $p=2$ removes the first $2$ elements $0,1$, resulting in $A = (-1)$. The sum of the elements removed is $1$, so $1 \times 3 = 3$ is added to the satisfaction, making it $10$.

There is no way to perform the operations that makes the satisfaction exceed $10$, so print $10$ as the answer.

Sample 2
Input
5 1
-5 1 -4 3 4
Output
-1

The satisfaction can take a negative value.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。