問題一覧 > 通常問題

No.919 You Are A Project Manager

レベル : / AI推定難易度 : 1600 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 57
作問者 : ningenMe / テスター : aajisaka
お気に入りにしたユーザー ProblemId : 3227 / 自分の提出
問題文最終更新日: 2020-12-06 13:04:48
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 229 (順位表) の他の問題:

Problem Statement

There are $N$ programmers standing in a row. The motivation of the $i$-th programmer from the left is $A_i$.
First, choose a positive number $K$.
Then, form some teams of $K$ people each by repeating the following operation any number of times.

・If $K$ or more programmers remain, remove $K$ consecutive programmers from the left end or the right end. These $K$ removed programmers form one team.

Here, $K$ cannot be changed once the operations have started.
The action power of one team is $K$×(the median of the motivation of the programmers in the team).
The median of the motivation is defined as follows: let $B_1,B_2, \dots\ B_K$ be the sequence of the motivation values of the team's programmers sorted in ascending order; the median is $B_{K/2}$ when $K$ is even and $B_{(K+1)/2}$ when $K$ is odd.

Find the maximum possible total action power when $K$ is chosen appropriately and the teams are formed optimally.
Note that the action power when no teams are formed at all is $0$.

Input

$N$
$A_{1}\ A_{2}\ \dots\ A_{N}$

All inputs are integers.
$1 \le N \le 10^4$
$-10^9 \le A_i \le 10^9 (1 \le i \le N)$

Output

Print a newline at the end.

Sample

Sample 1
Input
3
1 -1 2
Output
3

When $K=1$, choosing the leftmost programmer $1$ and then the rightmost programmer $3$ achieves the maximum value $\ 1×1+1×2=3\ $.

Sample 2
Input
10
-1 2 -3 4 -5 6 -7 8 -9 10
Output
33

When $K=3$, choosing 3 people from the left end, 3 people from the right end, and 3 people from the left end achieves the maximum value.

Sample 3
Input
20
2 3 4 5 -120 -6 7 8 9 11 38 -21 34 22 2 11 10 -90 -20 -10
Output
165

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