問題一覧 > 通常問題

No.2840 RGB Plates

レベル : / AI推定難易度 : 2125 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 59
作問者 : milkcoffee / テスター : suo ygussany
お気に入りにしたユーザー ProblemId : 11032 / 自分の提出
問題文最終更新日: 2024-08-03 20:24:21
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 440 (順位表) の他の問題:

Problem Statement

There are $N$ apples. The weight of apple $i$ is $A_i$. There are also $3$ plates, painted red, green, and blue, respectively.

You will place all $N$ apples, each on exactly $1$ of the red, green, and blue plates.

Let $R,G,B$ be the sums of the weights of the apples on the red, green, and blue plates, respectively. The apples must be placed so that the following $2$ conditions are satisfied.

  • Every plate has $1$ or more apples on it.
  • $G=B$.

Find the maximum possible value of $R$. If there is no way to place the apples that satisfies the conditions, report that.

Input

$N$
$A_1$ $A_2$ $\cdots$ $A_N$

  • $3 \leq N \leq 3000$
  • $1 \leq A_i \leq 5000$
  • All inputs are integers.

Output

Output the answer as an integer. If there is no way to place the apples that satisfies the conditions, output -1.

Sample

Sample 1
Input
5
1 2 3 4 5
Output
9

If the plates for the $5$ apples are (green, green, blue, red, red), respectively, then $G=B=3$ and $R=9$.

Among the placements satisfying the conditions, the maximum value of $R$ is $9$.

Sample 2
Input
3
1 2 3
Output
-1

Every plate must have $1$ or more apples on it. There is no way to place the apples that satisfies the condition $G=B$.

Sample 3
Input
11
59 927 349 933 1451 453 2000 975 345 782 123
Output
4733

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