Buy electronics

Subject:
Insert picture description here
Insert picture description here
Code:

#!/bin/python3

import os
import sys

#
# Complete the getMoneySpent function below.
#
def getMoneySpent(keyboards, drives, b):
    #
    # Write your code here.
    #
    keyboards_sort = sorted(keyboards)
    drives_sort = sorted(drives)
    if len(keyboards) == 1 or len(drives) == 1 or keyboards_sort[0] + drives_sort[0] > b:
        return -1
        
    res_set = set()
    for i in range(len(keyboards_sort)):
        for j in range(len(drives_sort)):
            if keyboards_sort[i] + drives_sort[j] <= b:
                res_set.add(keyboards_sort[i] + drives_sort[j])
               
    res_list = sorted(res_set)
    return res_list[-1]
            
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()

If you think it's good, just like and follow the message~
Thank you for joining us~

Guess you like

Origin blog.csdn.net/BSCHN123/article/details/113565468