Ding Dong Ditch (4/5 groups, 65/100 points)

This commit is contained in:
2023-06-23 09:01:28 +00:00
parent b42a481f09
commit 88a34c1912

20
dingdongditch.py Normal file
View File

@@ -0,0 +1,20 @@
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))