Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 365a03b

Browse files
Update
1 parent 09ec03d commit 365a03b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

‎algorithms/24_electronics-shop.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/python3
2+
3+
import os
4+
import sys
5+
6+
#
7+
# Complete the getMoneySpent function below.
8+
#
9+
def getMoneySpent(keyboards, drives, b):
10+
#
11+
# Write your code here.
12+
#
13+
ls = []
14+
for i in range(len(keyboards)):
15+
for j in range(len(drives)):
16+
total = keyboards[i]+drives[j]
17+
if b>=total:
18+
ls.append(total)
19+
try:
20+
jo = max(ls)
21+
if jo<=b:
22+
return jo
23+
except:
24+
return -1
25+
26+
if __name__ == '__main__':
27+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
28+
29+
bnm = input().split()
30+
31+
b = int(bnm[0])
32+
33+
n = int(bnm[1])
34+
35+
m = int(bnm[2])
36+
37+
keyboards = list(map(int, input().rstrip().split()))
38+
39+
drives = list(map(int, input().rstrip().split()))
40+
41+
#
42+
# The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
43+
#
44+
45+
moneySpent = getMoneySpent(keyboards, drives, b)
46+
47+
fptr.write(str(moneySpent) + '\n')
48+
49+
fptr.close()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /