-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectronics-shop.py
More file actions
28 lines (22 loc) · 1.04 KB
/
electronics-shop.py
File metadata and controls
28 lines (22 loc) · 1.04 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
# Solution for the problem "Electronics Shop"
# https://www.hackerrank.com/challenges/electronics-shop/problem
# Cash in hand, number of keyboard brands and number of usb brands
cash, numKeyboards, numUSB = map(int, input().strip().split(' '))
# List of keyboard prices
keyPrices = list(map(int, input().strip().split(' ')))
# List of USB prices
usbPrices = list(map(int, input().strip().split(' ')))
# -1 denotes that the money cannot be spent. We start here and then verify whether
# there is any possible combination of keyboard and usb within the budget
moneyToSpend = -1
# loop over keyboard prices
for keyPrice in keyPrices:
# loop over usb prices
for usbPrice in usbPrices:
# Sum of the current keyboard and usb
sumPrice = keyPrice + usbPrice
# If the current combination of keyboard and usb costs more than the existing
# seletion and it is within the available cash budget, we update the cost
if sumPrice > moneyToSpend and sumPrice <= cash:
moneyToSpend = sumPrice
print(moneyToSpend)