Codeforces Beta Round 34(Div. 2)
B
出售
Sale
Codeforces
900
原题
← AC →

出售AI (CI翻译)

Once Bob got to a sale of old TV sets. There were $*n*$ TV sets at that sale. TV set with index $*i*$ costs $*a*_{*i*}$ bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most $*m*$ TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.

鲍勃来到了一个旧电视机的售卖活动现场。那里有 $*n*$ 台电视机。编号为 $*i*$ 的电视机售价为 $*a*_{*i*}$ 贝拉。有些电视机的价格为负数——它们的所有者愿意在鲍勃买下这些无用设备时付钱给他。鲍勃可以“购买”任意数量、任意选择的电视机。尽管鲍勃力气很大,但他最多只能搬运 $*m*$ 台电视机,并且不想再次前往售卖活动现场。请帮助鲍勃求出他最多能赚到的钱数。AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first line contains two space-separated integers $*n*$ and $*m*$ ($1 ≤ *m* ≤ *n* ≤ 100$) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains $*n*$ space-separated integers $*a*_{*i*}$ ($- 1000 ≤ *a*_{*i*} ≤ 1000$) — prices of the TV sets.

第一行包含两个用空格分隔的整数 $*n*$ 和 $*m*$($1 ≤ *m* ≤ *n* ≤ 100$),分别表示售卖活动中的电视机数量,以及鲍勃最多能搬运的电视机数量。下一行包含 $*n*$ 个用空格分隔的整数 $*a*_{*i*}$($- 1000 ≤ *a*_{*i*} ≤ 1000$),表示各台电视机的价格。AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most $*m*$ TV sets.

输出一个整数,即在鲍勃最多搬运 $*m*$ 台电视机的情况下,他最多能赚到的钱数。 AI (CI翻译)

样例

Input #1
5 3
-6 0 35 -2 4
Output #1
8
InputCopy OutputCopy
Input #2
4 2
7 0 0 -7
Output #2
7
InputCopy OutputCopy
题目信息
题号
34B
时间限制
2 s
内存限制
256 MB
标签
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。