Files
kattis/dingdongditch.py

21 lines
426 B
Python

from functools import lru_cache
_, _ = map(int, input().split())
neighbours = sorted(map(int, input().split()))
friends = map(int, input().split())
total = sum(neighbours)
@lru_cache(maxsize=None)
def angry_value(i: int) -> int:
global neighbours
global total
if i > len(neighbours):
return total
else:
return sum(neighbours[:friend])
for friend in friends:
print(angry_value(friend))