[HackerRank] Electronics Shop
947 단어 hackerrankhackerrank
[문제 링크]
[입력]
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
Author And Source
이 문제에 관하여([HackerRank] Electronics Shop), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jongmin97/HackerRank-Electronics-Shop저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)