No.1046 Fruits Rush
タグ : / 解いたユーザー数 520
作問者 :
stoq
/ テスター :
fukafukatani
Problem Statement
There are $N$ fruits, and the freshness of the $i$-th fruit is $A_i$.
You will choose at least $1$ and at most $K$ of these fruits to make a mixed juice.
The deliciousness of the mixed juice is defined as the sum of the freshness of the chosen fruits.
Find the maximum possible deliciousness.
Input
$N\ K$ $A_1\ A_2\ \dots \ A_N$
$N,K,A_i$ are integers.
$1 \leq K \leq N \leq 100$
$|A_i| \leq 100$
Output
Output the maximum possible deliciousness. Print a newline at the end.
Sample
Sample 1
Input
3 2
1 3 2
Output
5
It is optimal to choose the fruits with freshness 2, 3.
Sample 2
Input
4 3
1 2 -1 -2
Output
3
It is optimal to choose the fruits with freshness 1, 2.
Note that you do not have to choose exactly $K$ fruits.
Sample 3
Input
5 5
0 0 0 0 0
Output
0
It is neither delicious nor bad.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。