-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_10.py
23 lines (18 loc) · 948 Bytes
/
core_10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# You found two items in a treasure chest! The first item weighs weight1 and is worth value1,
# and the second item weighs weight2 and is worth value2. What is the total maximum value of the items you can take with you,
# assuming that your max weight capacity is maxW and you can't come back for the items later?
# Note that there are only two items and you can't bring more than one item of each type, i.e. you can't take two first items or two second items.
def solution(value1, weight1, value2, weight2, maxW):
if (weight1+weight2)<=maxW:
return value1+value2
if (weight1+weight2)>maxW:
if all([weight1>maxW, weight2>maxW]):
return 0
elif all([weight1<maxW, weight2>maxW]):
return value1
elif all([weight1>maxW, weight2<maxW]):
return value2
# if weight1==maxW:
# return value1
# return value2
print(solution(10, 2, 11, 3, 1))