• + 13 comments

    Your solution SHOULD be in the Editorial! This is how it could look like in Python 2:

    #!/bin/python
    
    import sys
    
    def getMoneySpent(keyboards, drives, n, m, s):
        keyboards.sort(reverse=True)
        drives.sort()
        ms = -1
        i = j = 0
        while i < n:
            while j < m:
                if keyboards[i]+drives[j] > s:
                    break
                if keyboards[i]+drives[j] > ms:
                    ms = keyboards[i]+drives[j]
                j += 1
            i += 1
        return ms
    
    s,n,m = raw_input().strip().split(' ')
    s,n,m = [int(s),int(n),int(m)]
    keyboards = map(int, raw_input().strip().split(' '))
    drives = map(int, raw_input().strip().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, n, m, s)
    print(moneySpent)