Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))

    dic = {}
    for i in range(A):
        dic[i]={}
    for i in range(A):
        for j in range(B):
            dic[i][j] = 0


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()


Fixed submission:
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))

    dic = {}
    for i in range(A):
        dic[i]={}
    for i in range(A):
        for j in range(B):
            dic[i][j] = 0


    x_y_c_list = []

    for i in range(M):
        temp = list(map(int, input().split(' ')))
        x_y_c_list.append(temp)

        if dic[temp[0]-1][temp[1]-1] == 0:
            dic[temp[0]-1][temp[1]-1] = temp[2]
        else:
            if dic[temp[0]-1][temp[1]-1] < temp[2]:
                dic[temp[0]-1][temp[1]-1] = temp[2]

    price_list = -1
    for i in range(A):
        for j in range(B):
            if price_list == -1:
                price_list = a_list[i]+b_list[j] - dic[i][j]
            elif price_list > a_list[i]+b_list[j] - dic[i][j]:
                price_list = a_list[i]+b_list[j] - dic[i][j]
            else:
                price_list = price_list
            #price_list.append(a_list[i]+b_list[j] - dic[i][j])

    print(price_list)

if __name__=='__main__':
    main()


Fixed submission:
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))

    dic = {}
    for i in range(A):
        dic[i]={}
    for i in range(A):
        for j in range(B):
            dic[i][j] = 0


    x_y_c_list = []

    for i in range(M):
        temp = list(map(int, input().split(' ')))
        x_y_c_list.append(temp)

        if dic[temp[0]-1][temp[1]-1] == 0:
            dic[temp[0]-1][temp[1]-1] = temp[2]
        else:
            if dic[temp[0]-1][temp[1]-1] < temp[2]:
                dic[temp[0]-1][temp[1]-1] = temp[2]

    price_list = []
    for i in range(A):
        for j in range(B):
            price_list.append(a_list[i]+b_list[j] - dic[i][j])

    print(min(price_list))

if __name__=='__main__':
    main()


Fixed submission:
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))

    x_y_c_list = []

    for i in range(M):
        x_y_c_list.append(list(map(int, input().split(' '))))

    price_list = []
    for i in range(A):
        for j in range(B):
            for k in x_y_c_list:
                if k[:2] == [i+1, j+1]:
                    price_list.append(a_list[i]+b_list[j] - k[2])
                price_list.append(a_list[i]+b_list[j])

    print(min(price_list))

if __name__=='__main__':
    main()


Fixed submission:
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()