AtCoder Beginner Contest 067 - Snake Toy

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: EASY

Starter code:

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


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


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


(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()
l = l[n - k:n]
print(sum(l))


(n, k, *l) = map(int, open(0).read().split())
print(sum(sorted(l)[n - k:]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
print(sum(sorted(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())
(*L,) = map(int, input().split())
print(sum(sorted(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) = map(int, input().split())
l = sorted(list(map(int, input().split())))
print(sum(l[-1:-K - 1:-1]))


(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()
print(sum(l[N - K:N]))


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


(n, k) = map(int, input().split())
print(sum(sorted(list(map(int, input().split())), reverse=1)[: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, 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 = [int(i) for i in input().split()]
print(sum(sorted(L)[-k:]))


(n, k) = map(int, input().split())
(*l,) = map(int, input().split())
l = sorted(l, reverse=True)
print(sum(l[: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) = map(int, input().split())
L = list(map(int, input().split()))
KL = sorted(L)
print(sum(KL[-k:]))


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


(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 = list(map(int, input().split()))
l.sort()
l = l[::-1]
print(sum(l[0:k]))


(_, k) = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
print(sum(l[-k:]))


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


(N, K) = map(int, input().split())
A = sorted([int(a) for a in input().split()])
print(sum(A[-K:]))


(n, k) = map(int, input().split())
l = map(int, input().split())
s = sorted(l)[::-1]
print(sum(s[: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, m) = map(int, input().split(' '))
s = sorted(list(map(int, input().split(' '))))
print(sum(s[n - m:]))


(n, m) = map(int, input().split())
a = sorted([int(i) for i in input().split()])
print(sum(a[-m:]))


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


(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 = [int(x) for x in input().split()]
l.sort()
l.reverse()
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 = sorted(l)
x = 0
for i in range(-1, -1 - k, -1):
	x += l[i]
print(x)


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


(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())
a = sorted(list(map(int, input().split())))[::-1]
print(sum(a[:k]))


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


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


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


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


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


(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)


(N, K) = map(int, input().split())
I = sorted(map(int, input().split()))
print(sum(I[-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 = sorted(list(map(int, input().split())))[::-1]
print(sum(a[:K]))


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())
(*L,) = 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)
ans = 0
for i in range(k):
	ans += l[i]
print(ans)


(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_hon, K_part) = map(int, input().split())
length = list(map(int, input().split()))
length.sort()
ans = sum(length[-K_part:])
print(ans)


import sys
from typing import List
(n, k) = list(map(int, input().split()))
ll = list(map(int, input().split()))
bar = sorted(ll)[::-1]
ans = sum(bar[0:k])
print(ans)


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


(N, K) = map(int, input().split())
l = [int(s) for s in input().split()]
l.sort()
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(' ')))
length = list(map(int, input().split(' ')))
length.sort(reverse=True)
max_length = sum(length[:k])
print(max_length)


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


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


m = lambda : map(int, input().split())
(N, K) = m()
print(sum(sorted(m())[-K:]))


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


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


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


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


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


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


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


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


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


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


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


(_, k) = [int(i) for i in input().split()]
print(sum(sorted((int(i) for i in input().split()))[-k:]))


I = lambda : map(int, input().split())
(_, K) = I()
print(sum(sorted(I())[-K:]))


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


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


(t, l) = open(0)
print(sum(sorted(map(int, l.split()))[-int(t[2:]):]))


(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)


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


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


k = int(input().split()[1])
print(sum(sorted([int(x) for x in input().split()], reverse=1)[:k]))


(n, k, *l) = map(int, open(0).read().split())
l.sort(reverse=True)
print(sum(l[0: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()


(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())
a = list(map(int, input().split()))
a.sort(reverse=1)
print(sum(a[: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 = sorted([int(_) for _ in input().split()])
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()]
a = [int(x) for x in input().split()]
a.sort()
print(sum(a[n - k:n]))


(N, K) = map(int, input().split())
L = sorted(list(map(int, input().split())))
ans = sum(L[-K:])
print(ans)


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


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


(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, K) = map(int, input().split())
l = sorted(map(int, input().split()))
print(sum(l[-K:]))


(_, k) = map(int, input().split())
print(sum(sorted(list(map(int, input().split())))[-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())
Is = list(map(int, input().split()))
Is.sort()
print(sum(Is[-k:]))


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())
print(sum(sorted(list(map(int, input().split())))[::-1][0:K]))


f = lambda : map(int, input().split())
(_, k) = f()
l = sorted(list(f()))
print(sum(l[-k:]))


(N, K) = map(int, input().split())
L = sorted(list(map(int, input().split())))[::-1]
print(sum(L[: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())
li = sorted(list(map(int, input().split())))
print(sum(li[-k::1]))


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(sum(a[N - 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, M) = map(int, input().split())
L = sorted(list(map(int, input().split())))
print(sum(L[-M:]))


(N, K, *l) = map(int, open(0).read().split())
print(sum(sorted(l)[-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())
li = sorted([int(x) for x in input().split()])
print(sum(li[-k:]))


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


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
del s[:a - b]
print(sum(s))


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


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


(N, K) = map(int, input().split())
l = map(int, input().split())
print(sum(sorted(l)[::-1][0: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()


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


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


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)
main()


(n, k, *L) = map(int, open(0).read().split())
print(sum(sorted(L)[-k:]))


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


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


(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()))
l2 = sorted(l, reverse=True)
length = sum(l2[0:k])
print(length)


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


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


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


(N, K) = map(int, input().split())
L = [int(n) for n in input().split()]
print(sum(sorted(L)[N - K:]))


(N, K) = map(int, input().split())
ln = sorted(list(map(int, input().split())))
print(sum(ln[len(ln) - K:]))


(a, b) = list(map(int, input().split()))
final = list(map(int, input().split()))
final.sort(reverse=True)
print(sum(final[:b]))