問題一覧 > 通常問題

No.2028 Even Choice

レベル : / AI推定難易度 : 1625 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 130
作問者 : Shirotsume / テスター : ygussany とりゐ
お気に入りにしたユーザー ProblemId : 8187 / 自分の提出
問題文最終更新日: 2022-08-05 19:47:26
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. Back to the original
yukicoder contest 355 (順位表) の他の問題:

Problem Statement

$N$ cards are arranged in a horizontal row. Initially, the $i$-th card from the left $(1 \leq i \leq N)$ has the integer $A_i$ written on it. You perform the following operation exactly $K$ times.

  • Let $M$ be the number of cards currently remaining. Choose an even number $i$ satisfying $1 \leq i \leq M$, and remove the $i$-th card from the left among the remaining cards.

Find the maximum possible value of the sum of the integers written on the $K$ cards removed after performing the operation $K$ times.

Constraints

  • All inputs are integers
  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq K \leq N - 1$
  • $1 \leq A_i \leq 10^9$ $(1 \leq i \leq N)$

Input

The input is given from standard input in the following format.

$N$ $K$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Output the maximum possible value of the sum of the integers written on the $K$ removed cards. Print a newline at the end.

Sample

Sample 1
Input
5 3
3 1 4 1 5
Output
10

By performing the operations as follows, the sum of the integers written on the removed cards can be made $10$.

  • 1st operation: The remaining cards are $(3, 1, 4, 1, 5)$. Remove the $2$-nd card from the left.
  • 2nd operation: The remaining cards are $(3, 4, 1, 5)$. Remove the $4$-th card from the left.
  • 3rd operation: The remaining cards are $(3, 4, 1)$. Remove the $2$-nd card from the left.

No sequence of operations can make the sum of the integers greater than $10$.

Sample 2
Input
4 2
1 2 3 4
Output
6

Sample 3
Input
15 9
883548341 954946168 431651126 981968995 420220260 985870634 94232609 265487324 775722477 261574734 187926860 707452572 931578547 977913086 935287414
Output
7682391019

The output may not fit in a 32-bit integer.

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