Buggy python submission (verdict: Runtime Error):
def resolve():
    input = sys.stdin.readline
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)

    for x, y, c in grid:
        res = min(res, a[x-1]+b[y-1]-c)

    print(res)
    
resolve()

Fixed submission:
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)
    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = a[m[0]-1] + b[m[1]-1] - m[2]
        
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid=[list(map(int,input().split())) for i in range(M)]

    totals = []
    for i in a:
        total = [i+j for j in b]   
        totals.append(total)

    res = min(a) + min(b)
    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = totals[m[0]-1][m[1]-1] - m[2]
    
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

Fixed submission:
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)
    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = a[m[0]-1] + b[m[1]-1] - m[2]
        
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    grid=[list(map(int,input().split())) for i in range(M)]

    totals = []
    res = 10000 + 10000
    for i in range(A):
        total = []
        for j in range(B):
            value = a[i]+b[j]
            total.append(value)
            if value < res:
                res = value
        
        totals.append(total)

    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = totals[m[0]-1][m[1]-1] - m[2]
    
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

Fixed submission:
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)
    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = a[m[0]-1] + b[m[1]-1] - m[2]
        
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid = []
    for i in range(M):
        array = list(map(int, input().strip().split()))
        grid.append(array)

    totals = []
    res = 10000 + 10000
    for i in range(A):
        total = []
        for j in range(B):
            value = a[i]+b[j]
            total.append(value)
            if value < res:
                res = value
        
        totals.append(total)

    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = totals[m[0]-1][m[1]-1] - m[2]
    
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

Fixed submission:
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)
    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = a[m[0]-1] + b[m[1]-1] - m[2]
        
            if tmp < res:
                res = tmp

    print(res)
    
resolve()