Sort by

recency

|

2436 Discussions

|

  • + 0 comments
    #!/bin/python3
    
    import os
    import sys
    
    #
    # Complete the getMoneySpent function below.
    #
    def getMoneySpent(keyboards, drives, b):
        resultado = -1
        for i in keyboards:
            for j in drives:
                if i+j <= b:
                    resultado = max(i+j,resultado)
                    
        return resultado
    
    
    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()
    
  • + 0 comments

    Mi solución en Python 3:

    def getMoneySpent(keyboards, drives, b):
        #
        # Write your code here.
        #
        resultado = -1
        for i in keyboards:
            for j in drives:
                if i+j <= b:
                    resultado = max(i+j,resultado)
                    
        return resultado
    
  • + 0 comments

    Python 2 pointers solution:

    def getMoneySpent(keyboards, drives, b):
        keyboards.sort(reverse=True)
        drives.sort()
        spent_money = -1
        
        i = 0
        j = 0
        
        while i < len(keyboards) and j < len(drives):
            total_arr = keyboards[i] + drives[j]
            if (total_arr > b):
                i = i + 1
            else:
                spent_money = max(spent_money,total_arr)
                j = j + 1
        return spent_money
    
  • + 0 comments

    Python

    def getMoneySpent(keyboards, drives, b):
        possible = -1
        for i in keyboards:
            for j in drives:
                if i+j <= b:
                    possible = max(possible, i+j)
        return possible
    
  • + 0 comments

    def getMoneySpent(keyboards, drives, b): # # Write your code here. # prices=[] for i in range(len(keyboards)): price1=[keyboards[i]+drives[j] for j in range(len(drives)) if keyboards[i]+drives[j]<=b] prices.extend(price1) if prices!=[]: old=max(prices) else :old=-1
    return old