Snuke has N sticks.
The length of the i-th stick is l_i.
Snuke is making a snake toy by joining K of the sticks together.
The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.

-----Constraints-----
 - 1 \leq K \leq N \leq 50
 - 1 \leq l_i \leq 50
 - l_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N K
l_1 l_2 l_3 ... l_{N}

-----Output-----
Print the answer.

-----Sample Input-----
5 3
1 2 3 4 5

-----Sample Output-----
12

You can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.

Difficulty: introductory

Starter code:

Solutions:
N,K=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
sum=0
for i in range(K) :
  sum+=l[i]
print(sum)

n,k=map(int,input().split())
data=list(map(int,input().split()))
y=sorted(data)
s=0
for i in range(0,k):
    s=s+y[n-1-i]
print(s)

n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
al=sum(l)
for i in range(n-k):
    al -= l[i]
print(al)

n, k = map(int, input().split())
l = list(map(int, input().split()))

l = sorted(l, reverse=True)
print(sum(l[:k]))

n, k = map(int, input().split())
l = [int(s) for s in input().split()]

l.sort(reverse=True)
length = 0
for i in range(k):
    length += l[i]
print(length)

n,k=list(map(int,input().split()))
L=list(map(int,input().split()))
L.sort()
s=0
for i in range(n-k):
  s+=L[i]

print((sum(L)-s))


n,k=map(int, input().split())
l=list(map(int, input().split()))
l.sort(reverse=True)
print(sum(l[:k]))

a, b = list(map(int, input().split()))
final = list(map(int, input().split()))

final.sort(reverse = True)
print((sum(final[:b])))


n,k=list(map(int,input().split()))
l=list(map(int,input().split()))

L=sorted(l)

print((sum(L[(n-k):])))



# スペース区切りの整数の入力
n, k = map(int, input().split())
# スペース区切りの整数の入力
data =  list(map(int, input().split()))
l = sorted(data, reverse=True)
ans = 0

for i in range(k):
    ans += l[i]

print(ans)

a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
d=0
for i in range(b):
  d=d+c[-i-1]
print(d)

N, K = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
print(sum(l[-K:]))

n,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse = True)
ans = 0
for i in range(k):
  ans += l[i]
print(ans)

N, K = map(int, input().split())
ls = list(map(int, input().split()))
print(sum(sorted(ls, reverse=True)[:K]))

N, K = list(map(int, input().split()))
print((sum(sorted(map(int, input().split()), reverse=True)[:K])))


from typing import List


def answer(n: int, k: int, l: List[int]) -> int:
    l.sort(reverse=True)
    return sum(l[:k])


def main():
    n, k = list(map(int, input().split()))
    l = list(map(int, input().split()))
    print((answer(n, k, l)))


def __starting_point():
    main()

__starting_point()

# -*- coding: utf-8 -*-

N, K = map(int, input().split())
l = list(map(int, input().split()))

l_sorted = sorted(l, reverse=True)
total = 0
for i in range(K):
    total += l_sorted[i]

print(total)

lst = input().split()
N = int(lst[0])
K = int(lst[1])

L = input().split()
for i in range(N):
   L[i] = int(L[i])

L.sort(reverse=True)

ans = 0

for i in range(K):
   ans += L[i]

print(ans)

n,k = map(int,input().split())
data = list(map(int,input().split()))
data.sort(reverse = True)
ans = 0
for i in range(k):
    ans += data[i]
print(ans)

n, k = list(map(int, input().split()))
L = list(map(int,input().split()))
print((sum(sorted(L, reverse=True)[:k])))


N, K = map(int, input().split())
l = [int(l_) for l_ in input().split()]
l.sort(reverse=True)
print(sum(l[0:K]))

N,K = map (int, input ().split ())
l = [int (x) for x in input().split()]
list.sort (l)
x = 0
for i in range (K):
  x += l[-i-1]
print (x)

N, K = map(int,input().split())
l = list(map(int,input().split()))

l.sort(reverse=True)
l_max3 = l[0 : K]
print(sum(l_max3))

n, k = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse=True)
print(sum(l[:k]))

with open(0) as f:
    N, K, *l = map(int, f.read().split())
l.sort(reverse=True)
print(sum(l[:K]))

def abc067b_snake_toy():
    n, k = map(int, input().split())
    l = sorted(list(map(int, input().split())), reverse=True)
    print(sum(l[0:k]))

abc067b_snake_toy()

n,k = list(map(int, input().split()))
li = list(map(int, input().split()))
li.sort(reverse=True)
sum = 0
for i in range(k):
    sum += li[i]
print(sum)



_,k,*l=map(int,open(0).read().split())
l.sort(reverse=True)
print(sum(l[:k]))

n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
print(sum(l[-k:]))

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(sum(a[-k:]))

N, K = list(map(int, input().split()))
L = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for i in range(K):
    ans += L[i]
print(ans)


N, K = map(int, input().split())
l = sorted(list(map(int, input().split())))
l.reverse()


print(sum(l[:K]))

n, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = 0
for i in range(k):
    ans += a[i]
print(ans)

n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse = True)
cnt = 0
for i in range(k):
    cnt += l[i]
print(cnt)

n, k = map(int, input().split())
L = sorted(list(map(int, input().split())), reverse=True)

print(sum(L[0:k]))

n,k=list(map(int ,input().split()))
l=list(map(int ,input().split()))
ans=0
sorted_l=l.sort()
l.reverse()
for i in range(0,k):
	ans+=l[i]
	
print(ans)


N, K = list(map(int, input().split()))
L = sorted(list(map(int, input().split())), reverse=True)

print((sum(L[:K])))




n,k=map(int, input().split())
l=list(map(int,input().split()))
l.sort()
l.reverse()
assert l.__len__()==n
ans=0
for i in range(k):
    ans+=l[i]
print(ans)

n,k = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
print(sum(l[0:k]))

N, K = map(int, input().split())
l = sorted(map(int, input().split()))[::-1]
sum = 0
count = 0

for L in l:
    count += 1
    sum += L
    if count == K:
        break
    
print(sum)

N_hon, K_part = map(int, input().split())
length = list(map(int, input().split()))

length.sort()
ans = sum(length[-K_part:])

print(ans)

N, K = map(int, input().split())
num_list = list(map(int, input().split()))

print(sum(sorted(num_list, reverse=True)[:K]))

import sys
from typing import List

n, k = list(map(int, input().split()))
ll = list(map(int, input().split()))

bar = sorted(ll)[::-1]
#bar2 = bar[::-1]
ans = sum(bar[0:k])

print(ans)


n,k = map(int,input().split())
l = sorted(list(map(int,input().split())),reverse=True)
print(sum(l[:k]))

n, k = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
x = 0
for i in range(-1, -1-k, -1):
    x += l[i]
print(x)

N, K = map(int, input().split())
l = list(map(int, input().split()))
new_l = sorted(l, reverse=True)

print(sum(new_l[0:K]))

N, K = map(int,input().split())
L = list(map(int,input().split()))
L.sort(reverse=True)

print(sum(L[:K]))

n, k = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort(reverse = True)
ans = 0
for i in range(0, k):
    ans += lst[i]

print(ans)

N, K=list(map(int, input().split()))
l=list(map(int, input().split()))
l.sort()
print((sum(l[-K:])))


n, k = list(map(int, input().split()))
l = sorted(list(map(int, input().split())), reverse=True)
res = l[:k]
print((sum(res)))


n,k=map(int,input().split())
l=list(map(int,input().split()))

l2=sorted(l, reverse=True)
length = sum(l2[0:k])
print(length)

n,k = map(int,input().split())
a = sorted(map(int,input().split()))
a.reverse()
print(sum(a[:k]))

# -*- coding: utf-8 -*-

N,K = list(map(int, input().split()))
j = list(map(int, input().split()))
ans = 0

j.sort()
for i in range(K):
    ans += j.pop()

print(ans)


#n = int(input())
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

l.sort(reverse=True)
print((sum(l[:k])))


n,k=map(int, input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[-k:]))

N, K = list(map(int, input().split()))
l = sorted(map(int, input().split()), reverse=True)

ans = 0
for i in range(K):
    ans += l[i]
print(ans)


n,k = map(int,input().split())
a = sorted(map(int,input().split()))[::-1]
print(sum(a[:k]))

n,k=map(int,input().split())
l=[int(x) for x in input().split()]
l.sort(reverse=True)
print(sum(l[0:k]))

n, k = map(int, input().split())
l = list(map(int, input().split()))


l.sort(reverse=True)
ans = sum(l[:k])

print(ans)

n, k = (int(x) for x in input().split())
L = [int(x) for x in input().split()]
ans = sum(sorted(L, reverse=True)[:k])
print(ans)

N,K=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
print(sum(l[0:K]))

a,b=map(int,input().split())
c=input().split()
c=[int(i) for i in c]
x=0
c.sort()
for i in range(b):
    x+=c[len(c)-i-1]
print(x)

n, k = map(int, input().split())
l = list(map(int, input().split()))
print(sum(sorted(l, reverse=True)[0:k]))


N, K = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse=True)
print(sum(l[:K]))

n,k = map(int,input().split())
li = list(map(int,input().split()))
li.sort(reverse=True)
tol = 0
for i in range(k):
    tol += li[i]
print(tol)

N, K = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
l.reverse()
ans = 0
for i in range(K):
    ans += l[i]
print(ans)

a,b = list(map(int,input().split()))
i = sorted(list(map(int,input().split())))

print((sum(i[-b:])))



N,K = map(int,input().split())
l = list(sorted(map(int,input().split())))[::-1]

print(sum(l[:K]))

N,K=map(int,input().split())
L=list(map(int,input().split()))
L.sort(reverse=True)
print(sum(L[:K]))

n, k = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
print(sum(s[n-k:]))

n, k = map(int, input().split())
l = list(map(int, input().split()))
l_sort = sorted(l)
print(sum(l_sort[-k:]))

n, k = list(map(int, input().split(' ')))
length = list(map(int, input().split(' ')))
length.sort(reverse=True)
max_length = sum(length[:k])
print(max_length)



n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)
sum = 0
for i in range(k):
    sum = sum + a[i]
print(sum)

N,K = list(map(int, input().split()))
S = list(map(int, input().split()))

S = sorted(S,reverse=True)

print((sum(S[:K])))


#!/usr/bin/env python3


def main():
    N, K, *L = list(map(int, open(0).read().split()))
    L.sort()
    print((sum(L[-K:])))


main()


n, k = map(int, input().split())
l = sorted(list(map(int, input().split())),reverse=True)
print(sum(l[:k]))

n,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse=True)
print(sum(l[:k]))

N, K = map(int,input().split())
l = list(map(int,input().split()))

l.sort(reverse=True)
snake = []

for i in range(K):
    snake.append(l[i])

print(sum(snake))

n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]

a.sort(reverse=True)
print((sum(a[:k])))


N, K = map(int, input().split())
L = list(map(int, input().split()))

L.sort()
L.reverse()

print(sum(L[:K]))

# coding: utf-8

num, choose_num = map(int, input().split())
total = 0
stick_length = input().split(" ")

str_num = [int(n) for n in stick_length]
list.sort(str_num, reverse=True)

for i in range(choose_num):
    total += str_num[i]

print(total)

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans = 0
for i in range(k):
  ans += a[i]
print(ans)

k = list(map(int, input().split()))[1]
ls = list(sorted(list(map(int, input().split()))))
print((sum(ls[len(ls) - k:])))


n, k = map(int, input().split())
l = list(map(int, input().split()))

l_sorted = sorted(l, reverse = True)
snake = 0
for i in range(k):
    snake += l_sorted[i]
print(snake)

N, K = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
Sum = 0

for i in range(K):
    Sum += l[N - i - 1]

print(Sum)


N,K=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
print((sum(l[N-K:N])))


a,b=list(map(int,input().split()))
N = sorted(list(map(int,input().split())))[::-1]
print((sum(N[:b])))


N, K = map(int, input().split())
L = list(map(int, input().split()))

L = sorted(L, reverse=True)
print(sum(L[:K]))

a,b=map(int,input().split())
le=list(map(int,input().split()))
le.sort()
gou=0
for i in range(b):
  gou+=le.pop()
print(gou)

N, K = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]

s = sorted(l)

ans = sum(s[N - K:])

print(ans)

n, k = map(int, input().split())
l = sorted(list(map(int, input().split())))[::-1]

print(sum(l[:k:]))

N,K = list(map(int,  input().split()))
lengths_list = list(map(int, input().split()))
lengths_list.sort()
lengths_list.reverse()
sum_length = 0
for i in range(K):
    sum_length += lengths_list[i]

print(sum_length)


n, k = map(int, input().split())
lst = list(map(int, input().split()))

lst = sorted(lst)
print(sum(lst[(-1) * k:]))

_,k=map(int,input().split());print(sum(sorted(map(int,input().split()))[-k:]))

# B - Snake Toy
def main():
    _, k = map(int, input().split())
    l = list(map(int, input().split()))
    cnt = 0
    l.sort(reverse=True)

    for i in range(k):
        cnt += l[i]
    else:
        print(cnt)



if __name__ ==  "__main__":
    main()

#!/usr/bin/env python3
N, K = list(map(int, input().split()))
L = sorted(list(map(int, input().split())))
print((sum(L[-K:])))


n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
print(sum(a[n-k:n]))

N, K = list(map(int, input().split()))
L = list(map(int, input().split()))

L.sort()
print((sum(L[-K:])))


n,k=map(int,input().split())
s=list(map(int,input().split()))
s.sort(reverse=True)

print(sum(s[0:k]))

n,k = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
print(sum(l[:k]))