-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectronics Shop
More file actions
67 lines (35 loc) · 1.09 KB
/
Electronics Shop
File metadata and controls
67 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/python3
import os
import sys
#
# Complete the getMoneySpent function below.
#
def getMoneySpent(keyboards, drives, b):
keyboards.sort(reverse=True)
drives.sort(reverse=True)
n=len(keyboards)
m=len(drives)
res=[]
if keyboards[-1]>= b or drives[-1]>=b:
if keyboards[-1] + drives[-1] >= b:
return -1
for i in range(0,n):
for j in range(0,m):
cost = keyboards[i]+drives[j]
if cost <= b:
res.append(cost)
return max(res)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
bnm = input().split()
b = int(bnm[0])
n = int(bnm[1])
m = int(bnm[2])
keyboards = list(map(int, input().rstrip().split()))
drives = list(map(int, input().rstrip().split()))
#
# The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
#
moneySpent = getMoneySpent(keyboards, drives, b)
fptr.write(str(moneySpent) + '\n')
fptr.close()