34B. Sale
greedy, sorting, 900, https://codeforces.com/problemset/problem/34/B
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs
Input
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
Output
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
Examples
Input
5 3
-6 0 35 -2 4Output
8Input
4 2
7 0 0 -7Output
7思路:排序后,找出需要的负数。
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(m):
if a[i] > 0:
break
ans += a[i]
print(-ans)