From 88a34c1912a3ac72161f10c7eb9348620e65d8b2 Mon Sep 17 00:00:00 2001 From: Jethro Stapelbroek Date: Fri, 23 Jun 2023 09:01:28 +0000 Subject: [PATCH] Ding Dong Ditch (4/5 groups, 65/100 points) --- dingdongditch.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 dingdongditch.py diff --git a/dingdongditch.py b/dingdongditch.py new file mode 100644 index 0000000..71365a9 --- /dev/null +++ b/dingdongditch.py @@ -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))