No.2840 RGB Plates
タグ : / 解いたユーザー数 59
作問者 :
milkcoffee
/ テスター :
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もしくは右上の雲マークをクリックしてアカウントを作成してください。