Best Gadget Pair
A shopper wants to buy exactly one keyboard and one drive without going over budget. The function get_money_spent receives price lists keyboards and drives, plus the budget b. Find the highest possible combined price that does not exceed the budget. If no pair can be bought, return -1.
Примеры
Ввод
[3, 1], [5, 2, 8], 10Вывод
9Ввод
[4], [5], 5Вывод
-1Ввод
[40, 50, 60], [5, 8, 12], 60Вывод
58Нужно реализовать
def get_money_spent(keyboards: list[int], drives: list[int], b: int) -> int:
Теги
arraytwo-pointersmath
Melde dich an, um den Einreichungsverlauf zu sehen
AnmeldenMelde dich an, um den KI-Mentor zu nutzen
AnmeldenVisible tests
1
Input
[3,1], [5,2,8], 10Expected
92
Input
[4], [5], 5Expected
-13
Input
[40,50,60], [5,8,12], 60Expected
584
Input
[1,2,3], [4,5,6], 100Expected
95
Input
[10], [10], 20Expected
206
Input
[4,2], [5,2,8,5,2], 9Expected
9Focus radio
Paused · SomaFM · Fluid