[HackerRank] Electronics Shop

Jongmin Lee (SAVZAK)·2021년 6월 9일
0

HackerRank

목록 보기
12/39

[문제 링크]

[입력]

int keyboards[n]: the keyboard prices array , size is n
int drives[m]: the drive prices array , size is m
int b: the budget

[출력]

int: the maximum that can be spent, or -1 if it is not possible to buy both items

[코드]

def getMoneySpent(keyboards, drives, b):

    result = 0
    keyboards.sort()
    drives.sort()
    
    if(keyboards[0]+drives[0]>b):
        return -1
    
    for i in range(len(keyboards)):
        for j in range(len(drives)):
            if(keyboards[i]+drives[j]<=b and result<= keyboards[i]+drives[j]):
                result = keyboards[i]+drives[j]
    return result
profile
느리지만 단단하게 걷는 개발자

0개의 댓글