Answer the question
In order to leave comments, you need to log in
How to make the algorithm repeatedly execute until some condition is met?
I have an algorithm:
n = int(input())
arr = [ int(input()) for i in range(n) ]
teaMin = int(input())
sm = sum(arr)
sums = set()
sums.add(0)
arr.sort()
for item in arr:
for k in range(sm, min(arr) - 1, -1):
if (k - item) in sums:
sums.add(k)
[2,3,5]
[2, 3, 5, (5+2)7, (5+3)8, ((2+3)+5)10, (there is no element that satisfies the condition, so the second circle)(10+2)12 , (10+3)13, (10+5)15 ... 30, (30+2)32
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question