Problem:
 Score : 200 points    Problem Statement  You are visiting a large electronics store to buy a refrigerator and a microwave.  The store sells A kinds of refrigerators and B kinds of microwaves. The i -th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j -th microwave ( 1 \le j \le B ) is sold at b_j yen.  You have M discount tickets. With the i -th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i -th refrigerator and the y_i -th microwave together. Only one ticket can be used at a time.  You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.      Constraints   All values in input are integers.  1 \le A \le 10^5  1 \le B \le 10^5  1 \le M \le 10^5  1 \le a_i , b_i , c_i \le 10^5  1 \le x_i \le A  1 \le y_i \le B  c_i \le a_{x_i} + b_{y_i}         Input  Input is given from Standard Input in the following format:  A  B  M  a_1  a_2  ...  a_A  b_1  b_2  ...  b_B  x_1  y_1  c_1  \vdots  x_M  y_M  c_M       Output  Print the answer.        Sample Input 1 2 3 1
3 3
3 3 3
1 2 1      Sample Output 1 5  With the ticket, you can get the 1 -st refrigerator and the 2 -nd microwave for 3+3-1=5 yen.       Sample Input 2 1 1 2
10
10
1 1 5
1 1 10      Sample Output 2 10  Note that you cannot use more than one ticket at a time.       Sample Input 3 2 2 1
3 5
3 5
2 2 2      Sample Output 3 6  You can get the 1 -st refrigerator and the 1 -st microwave for 6 yen, which is the minimum amount to pay in this case.
Note that using a ticket is optional.

Solution (Python):
i = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_cost=min(a)+min(b)
for j in range(i[2]):
    x = list(map(int, input().split()))
    if (a[x[0]-1]+b[x[1]-1]-x[2])<min_cost:
        min_cost=(a[x[0]-1]+b[x[1]-1]-x[2])
print(min_cost)

Solution (Python):

A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
m = [list(map(int,input().split())) for i in range(M)]
n = list()

min_a = min(a)
min_b = min(b)
sa = min_a + min_b
n.append(sa)

for i in range(M):
    su = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2]
    n.append(su)


ans = min(n)
print(ans)

Solution (Python):
listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

con=min(listA[1])+min(listA[2])
listB=[listA[1][listA[i+3][0]-1]+listA[2][listA[i+3][1]-1]-listA[i+3][2] for i in range(listA[0][2])]
print(min(con,min(listB)))

Solution (Python):
A,B,M=map(int, input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x = [0] * M
y = [0] * M
c = [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())



ans=min(a)+min(b)



for i in range(M):

    if ans>a[x[i]-1]+b[y[i]-1]-c[i]:
        ans=a[x[i]-1]+b[y[i]-1]-c[i]

print(ans)

Solution (Python):
a, b, m = map(int, input().split())
ax = list(map(int, input().split()))
bx = list(map(int, input().split()))
x = []
for i in range(m):
    _x = map(int, input().split())
    x.append(list(_x))

min_a = min(ax)
min_b = min(bx)
min_sum = min_a + min_b

for k in x:
    sum = ax[k[0]-1] + bx[k[1]-1] - k[2]
    if sum < min_sum:
        min_sum = sum

print("{}".format(min_sum))

Solution (Python):
A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
price_off = [dict(zip(["x", "y", "c"], map(int, input().split()))) for _ in range(M)]
result = [min(a) + min(b)]
result += [a[d["x"]-1] + b[d["y"]-1] - d["c"] for d in price_off]
print(min(result))

Solution (Python):

A,B,M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = [list(map(int, input().split())) for _ in range(M)]





p = min(a) + min(b) 

l=[]

for i in range(M):
    temp = a[x[i][0]-1] + b[x[i][1]-1] - x[i][2]
    l.append(temp)


print(min(p,min(l)))

Solution (Python):
A,B,M = map(int, input().split())



a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=[]
for i in range(M):
    m.append(input().split())

counta=0
countb=0
nummin=int(a[0])+int(b[0])
for i in m:
    
    x=int(i[0])-1
    y=int(i[1])-1
    c=int(i[2])
    num=a[x]+b[y]-c

    if num<nummin:
        nummin=num
if min(a)+min(b)<nummin:
    nummin=min(a)+min(b)

print(nummin)

Solution (Python):

A,B,M = list(map(int,input().split()))

a = list(map(int,input().split()))
b = list(map(int,input().split()))

mini = min(a)+ min(b)

def check(Mlist, mini):
    
    if mini > a[Mlist[0]-1]+b[Mlist[1]-1]-Mlist[2]:
        return a[Mlist[0]-1]+b[Mlist[1]-1]-Mlist[2]
    return mini
for i in range(M):
    mini = check(list(map(int,input().split())),mini)

print(mini)

Solution (Python):


a, b, m = map(int, input().split())
fridge = list(map(int, input().split()))
micro = list(map(int, input().split()))
c = []
for i in range(m):
    c.append(list(map(int, input().split())))
costs = []
for i in c:
    temp = fridge[i[0]-1]+micro[i[1]-1]-i[2]
    costs.append(temp)
fridge.sort()
micro.sort()
costs.append(fridge[0]+micro[0])
costs.sort()
print(costs[0])

Solution (Python):
A, B, M = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
mList = [list(map(int, input().split())) for i in range(M)]
Min = 20001

Min = min(aList) + min(bList)
for i in range(M):
    cost = aList[mList[i][0] -1] + bList[mList[i][1] -1] - mList[i][2]
    Min = min(Min, cost)

print(Min)

Solution (Python):
A,B,M = map(int,input().split())
A_ = list(map(int,input().split()))
B_ = list(map(int,input().split()))
mini =min(A_) + min(B_)
for i in range(M):
    array = list(map(int,input().split()))
    m = A_[array[0]-1] + B_[array[1]-1] -array[2]
    if(mini > m):
        mini = m
print(mini)

Solution (Python):
a, b, m = map(int, input().split())
pa = list(map(int, input().split()))
pb = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for j in range(m)]
minprice = min(pa)+min(pb)
wari=0
for i in xyc:
    wari = pa[i[0]-1]+pb[i[1]-1]-i[2]
    if wari<minprice:
        minprice = wari
print(minprice)

Solution (Python):
def totalprice_with_discount_ticket(ref, mic, discount_ticket):
    totalprice = min(ref) + min(mic)
    for t in discount_ticket:
        discnt_ref_num = t[0] - 1
        discnt_mic_num = t[1] - 1
        discnt_amt = t[2]
        if totalprice > ref[discnt_ref_num] + mic[discnt_mic_num] - discnt_amt:
            totalprice = ref[discnt_ref_num] + mic[discnt_mic_num] - discnt_amt

    return totalprice


if __name__ == '__main__':
    ref_num, mic_num, ticket_num = map(int, input().split())
    ref_list = list(map(int, input().split()))
    mic_list = list(map(int, input().split()))
    discount_ticket_list = [list(map(int, input().split()))
                            for i in range(ticket_num)]
    print(totalprice_with_discount_ticket(
        ref_list, mic_list, discount_ticket_list))

Solution (Python):
A, B, M  = map(int, input().split())
ta = input().split()
tb = input().split()
a = [int(s) for s in ta]
b = [int(s) for s in tb]
mp = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    w = a[x-1] + b[y-1] - c
    if mp > w:
        mp = w
print(mp)

Solution (Python):
a, b, m = map(int,input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))

ans = min(ai)+min(bi)
for k in range(m):
    ak, bk, mk = map(int,input().split())
    ansk = ai[ak-1]+bi[bk-1]-mk
    if ansk<ans:
        ans = ansk
print(ans)

Solution (Python):
a, b, m = map(int,str(input()).split())
a_cost_map = map(int,str(input()).split())
a_cost = list(a_cost_map)
b_cost_map = map(int,str(input()).split())
b_cost = list(b_cost_map)

coupons_map = [str(input()).split() for i in range(m)]
coupons_map_all =  [[int(coupons_map[i][t]) for t in range(len(coupons_map[i]))] for i in range(len(coupons_map))]

minimum = min(a_cost) + min(b_cost)
for coupon in coupons_map_all:
    coupon_use = (a_cost[coupon[0]-1] +  b_cost[coupon[1]-1] - coupon[2]) 
    if minimum > coupon_use:
        minimum = coupon_use
print(minimum)

Solution (Python):


def hitachi2020b(a, b, discount):
    min_a = a[0]
    for i in range(len(a)):
        if a[i] < min_a:
            min_a = a[i]
    min_b = b[0]
    for i in range(len(b)):
        if b[i] < min_b:
            min_b = b[i]
    min_val = min_a + min_b

    for k in range(len(discount)):
        disc = discount[k]
        cand_a = disc[0] - 1
        cand_b = disc[1] - 1
        cand_val = a[cand_a] + b[cand_b] - disc[2]
        if cand_val < min_val:
            min_val = cand_val

    return min_val



if(__name__ == '__main__'):
    
    num_a, num_b, m = map(int, input().split(" "))
    val_a = list(map(int, input().split(" ")))
    val_b = list(map(int, input().split(" ")))

    discount = []
    for k in range(m):
        discount.append(list(map(int, input().split(" "))))
    
    accomplishment = hitachi2020b(val_a, val_b, discount)
    
    
    print(accomplishment)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=float('inf')
for i in range(M):
    x,y,c=map(int,input().split())
    ans=min(a[x-1]+b[y-1]-c,ans)
ans=min(min(a)+min(b),ans)
print(ans)

Solution (Python):
aa, bb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

couponMin = float("INF")
for i in range(m):
    x, y, c = map(int, input().split())
    cc = a[x - 1] + b[y - 1] - c
    couponMin = min(couponMin, cc)

print(min(min(a) + min(b), couponMin))

Solution (Python):
A,B,M = map(int,input().split())
 
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
ticket = []
 
while M>0:
    ticket.append(tuple(map(int, input().split())))
    M -= 1
 
lowest = min(a)+min(b)
 
for ele in ticket:
    t = a[ele[0]-1] + b[ele[1]-1] - ele[2]
    if t < lowest:
        lowest = t
print(lowest)

Solution (Python):
A, B, M = input().split()
A=int(A)
B=int(B)
M=int(M)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(M)]
 
dis = []
for i in range(M):
    m = x[i][0]-1
    n = x[i][1]-1
    dis.append(a[m] + b[n] - x[i][2])
    
a.sort()
b.sort()
 
dis.append(a[0]+b[0])
 
print(min(dis))

Solution (Python):


def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    x = [0] * M
    y = [0] * M
    c = [0] * M
    for i in range(M):
        x[i], y[i], c[i] = map(int, input().split())

    
    total = min(a) + min(b)

    
    for i in range(M):
        t = a[x[i] - 1] + b[y[i] - 1] - c[i]
        if t < total:
            total = t

    print(total)

main()

Solution (Python):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = []
waribiki = []

for _ in range(M):
    x,y,c = map(int,input().split())
    waribiki.append(a[x-1]+b[y-1]-c)
a_min=min(a)
b_min=min(b)
ab_min = a_min+b_min
waribiki_min = min(waribiki)
print(min(waribiki_min,ab_min))

Solution (Python):
a, b, m = map(int, input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
xi = [list(map(int, input().split())) for i in range(m)]
ans = []
ans.append(min(ai)+ min(bi))
for i in range(0,m):
    ans.append(ai[xi[i][0]-1] + bi[xi[i][1]-1] - xi[i][2])

print(min(ans))

Solution (Python):
import itertools
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)
    
sum_fee = []
a_min = min(a)
b_min = min(b)
sum_fee.append(a_min+b_min)

for l, m, n in grid:
    sum_fee.append(a[l-1] + b[m-1] - n)
    

print(min(sum_fee))

Solution (Python):
a, b, m = map(int, input().split())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_m = [ list(map(int,input().split(" "))) for i in range(m)]

ans = []

ans.append(min(list_a)+min(list_b))

for i in range(m):
    k = list_m[i]
    ans.append(list_a[k[0]-1] + list_b[k[1]-1] - k[2])

print(min(ans))

Solution (Python):
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
w_list = []
for i in range(M):
    a, b, c = map(int, input().split())
    w_list.append(a_list[a - 1] + b_list[b - 1] - c)

print(min(min(w_list), min(a_list) + min(b_list)))

Solution (Python):
A, B, M=map(int,input().split())
list_A=list(map(int,input().split()))
list_B=list(map(int,input().split()))
list_1=[list(map(int,input().split())) for i in range(M)]
L=min(list_A)+min(list_B)
list_2=[]
for k in range(M):
  cost=list_A[list_1[k][0]-1]+list_B[list_1[k][1]-1]-list_1[k][2]
  list_2.append(cost)
if L>=min(list_2):
  print(min(list_2))
else:
  print(L)

Solution (Python):
a,b,m = map(int,input().split())
alist = list(int(x) for x in input().split())
blist = list(int(x) for x in input().split())
x = []
y = []
c = []
for i in range(m):
  inp1,inp2,inp3 = map(int,input().split())
  x.append(inp1)
  y.append(inp2)
  c.append(inp3)
mini = min(alist) ++ min(blist)
for i in range(m):
  if alist[x[i]-1] + blist[y[i]-1] - c[i] < mini:
    mini = alist[x[i]-1] + blist[y[i]-1] - c[i]
print(mini)

Solution (Python):
A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans, sav = float("inf"), 0
for j in range(M):
    sav = a[x[j] - 1] + b[y[j] - 1] - c[j]
    if ans > sav:
        ans = sav

print(min(ans, min(a) + min(b)))

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(M):
    X, Y, C= map(int, input().split())
    x.append(X-1)
    y.append(Y-1)
    c.append(C)

value = []
for i in range(M):
    v = a[x[i]] + b[y[i]] - c[i]
    value.append(v)

mindefalt = min(a) + min(b)
minvalue = min(value)

if mindefalt > minvalue:
    print(minvalue)
else:
    print(mindefalt)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
matrix = []
for i in range(M):
    matrix.append(list(map(int, input().split())))

ans = min(a) + min(b)
for i in range(M):
    if a[matrix[i][0]-1] + b[matrix[i][1]-1] - matrix[i][2] < ans:
        ans = a[matrix[i][0]-1] + b[matrix[i][1]-1] - matrix[i][2]
print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
min_price=min(a)+min(b)
for i in range(M):
    tmp_price=10000
    m=list(map(int,input().split()))
    tmp_price=a[m[0]-1]+b[m[1]-1]-m[2]
    if min_price>tmp_price:
        min_price=tmp_price
print(min_price)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for _ in range(M)]
ans=min(a)+min(b)
for x,y,c in xyc:
  ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Solution (Python):
numberOfDiscountTickets=input().split()[2]
refrigirators=input().split()
microwaves=input().split()
discounts=[]
for i in range(int(numberOfDiscountTickets)):
 discounts.append(input().split())
temp1=sorted(refrigirators)
temp2=sorted(microwaves)
minimumPrice=int(temp1[0])+int(temp2[0])
checkMin=0
for discount in discounts:
 checkMin=int(refrigirators[int(discount[0])-1])+int(microwaves[int(discount[1])-1])-int(discount[2])
 if checkMin<minimumPrice:
  minimumPrice=checkMin
print(minimumPrice)

Solution (Python):
a, b ,c = map(int,input().split(" "))
ap =[]
ap = list(map(int,input().split(" ")))
bp =[]
bp = list(map(int,input().split(" ")))
lowest = 10000000
ma = min(ap)
mb = min(bp)
lowest = ma +mb
for _ in range(c):
    x, y ,z = map(int,input().split(" "))
    dis = ap[x-1] + bp[y-1] - z
    lowest = min(lowest,dis)
print(lowest)

Solution (Python):
A,B,M = map(int,input().split())
 
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
ticket = []
 
while M>0:
    ticket.append(tuple(map(int, input().split())))
    M -= 1
 
lowest = min(a)+min(b)
 
for ele in ticket:
    t = a[ele[0]-1] + b[ele[1]-1] - ele[2]
    if t < lowest:
        lowest = t
print(lowest)

Solution (Python):
i=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=i[0]
B=i[1]
M=i[2]
x = []
y = []
c = []
for j in range(M):
    x1,y1,c1=[int(j) for j in input().split()]
    x.append(x1)
    y.append(y1)
    c.append(c1)
d=200001
e=100001
f=100001
for k in range (A):
    if a[k]<e:
        e=a[k]

for l in range (B):
    if b[l]<f:
        f=b[l]
d=e+f

for p in range (M):
    if a[x[p]-1]+b[y[p]-1]-c[p]<d:
        d= a[x[p]-1]+b[y[p]-1]-c[p]

print(d)

Solution (Python):
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min(min(a) + min(b), *(a[x - 1] + b[y - 1] - c for x, y, c in d)))

Solution (Python):

import numpy as np

A, B, M = input().split(" ")
a = np.array(input().split(" "), dtype=np.int64)
b = np.array(input().split(" "), dtype=np.int64)

x_list = []
for i in range(int(M)):
  temp = input().split(" ")
  x_list.append(temp)

x_np = np.array(x_list, dtype=np.int64)


a_min = a.min()
b_min = b.min()
a_min_idx = np.argmin(a)
b_min_idx = np.argmin(b)

cand = x_np[(x_np[:,0]==a_min_idx)&(x_np[:,1]==b_min_idx)]
if cand.shape[0]>0:
  tgt_idx = np.argmax(cand, axis=0)[2]
  cand_payment1 = a_min + b_min - cand[tgt_idx,2]
else:
  cand_payment1 = a_min + b_min
  

val_list = []
for x,y,c in x_np:
  val_list.append(a[x-1] + b[y-1] - c)
  
val_np = np.array(val_list)
cand_payment2 = val_np.min()


if cand_payment1<cand_payment2:
  print(cand_payment1)
else:
  print(cand_payment2)

Solution (Python):
import itertools

a,b,m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P = [list(map(int,input().split())) for i in range(m)]
y = []

aa = min(A)
bb = min(B)
xx =aa+bb


for i in range(m):
  y.append(A[P[i][0]-1] + B[P[i][1]-1] - P[i][2])

yy = min(y)

print(min(xx,yy))

Solution (Python):
A, B, M = map(int, input().split())
a, b = [], []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [], [], []
for i in range(M):
  tmp = list(map(int, input().split()))
  x.append(tmp[0])
  y.append(tmp[1])
  c.append(tmp[2])


min_a, min_b, min_total_wo = 10**5+1, 10**5+1, 0
for i in range(A):
  if min_a > a[i]:
    min_a = a[i]
for i in range(B):
  if min_b > b[i]:
    min_b = b[i]
min_total_wo = min_a + min_b
  

min_total_w = 2*10**5+1
for i in range(M):
  tmp = a[x[i]-1] + b[y[i]-1] - c[i]
  if min_total_w > tmp:
    min_total_w = tmp
if min_total_wo < min_total_w:
  print(min_total_wo)
else:
  print(min_total_w)

Solution (Python):


A, B, M = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

i = 200000


for j in range(M):
    
    
    c =  list(map(int, input().split()))
    ma = c[0] - 1
    mb = c[1] - 1
    h = a[ma] + b[mb] - c[2]

    if i >= h:
        i = h

m = min(a) + min(b)

if i >= m:
    i = m

print(i)

Solution (Python):


N_A, N_B, N_M = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
M = [list(map(int,input().split(" "))) for i in range(N_M)]

candidates = [min(A)+min(B),]

for m in M:
    
    candidates.append(A[m[0]-1] + B[m[1]-1] - m[2])

print(min(candidates))

Solution (Python):

a,b,m=map(int, input().split())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

m_l = []
for i in range(m):
    m_l.append(list(map(int, input().split())))
score = float('inf')
min_norm = min(a_l) + min(b_l)
sale_l = []
for m_ in m_l:
    sale_l.append(a_l[m_[0]-1]+b_l[m_[1]-1] - m_[-1])
print(min(min_norm,min(sale_l)))

Solution (Python):
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))


X = []
Y = []
C = []
total = 2*10**5
for i in range(m):
    x,y,c = map(int,input().split())
    X.append(x)
    Y.append(y)
    C.append(c)
for i in range(m):
    result = int(A[int(X[int(i)])-1])+int(B[int(Y[int(i)])-1])-int(C[int(i)])
    if (total > result):
        total = result

if(int(min(A))+int(min(B))>total):
    print(total)
else:
    print(int(min(A))+int(min(B)))

Solution (Python):
A,B,M = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
min_cost = min(a_list)+min(b_list)
for _ in range(M):
    x,y,c = map(int,input().split())
    cost = a_list[x-1] + b_list[y-1] -c
    if cost<min_cost:
        min_cost = cost
print(min_cost)

Solution (Python):
a,b,m=map(int, input().split())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
m_l = []
for i in range(m):
    m_l.append(list(map(int, input().split())))
score = float('inf')
min_norm = min(a_l) + min(b_l)
sale_l = []
for m_ in m_l:
    sale_l.append(a_l[m_[0]-1]+b_l[m_[1]-1] - m_[-1])
print(min(min_norm,min(sale_l)))

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = []
s.append(min(a) + min(b))

for i in range(M):
    x_i, y_i, c_i = map(int, input().split())
    minus = a[x_i - 1] + b[y_i - 1] - c_i
    s.append(minus)

print(min(s))

Solution (Python):
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min([min(a) + min(b)] + [a[x - 1] + b[y - 1] - c for x, y, c in d]))

Solution (Python):
abm = [int(n) for n in input().split()]

a = abm[0]
b = abm[1]
m = abm[2]
am, bm = 1000000, 1000000
al = [int(n) for n in input().split()]
bl = [int(n) for n in input().split()]
for i in al:
    if am > i:
        am = i
for i in bl:
    if bm > i:
        bm = i
ans = am + bm

for i in range(m):
    x, y, c = map(int, input().split())
    x = x - 1
    y = y - 1
    cur = al[x] + bl[y] - c
    if cur < ans:
        ans = cur

print(ans)

Solution (Python):
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
max=min(al)+min(bl)
for i in range (m):
    cl=list(map(int,input().split()))
    if(al[cl[0]-1]+bl[cl[1]-1]-cl[2]<max):
        max=al[cl[0]-1]+bl[cl[1]-1]-cl[2]
print(max)

Solution (Python):
A,B,M=input().split()
A=int(A)
B=int(B)
M=int(M)

a=[int(i) for i in input().split()]
b=[int(j) for j in input().split()]

z=min(a)+min(b)
m=0
while m<M:
  s=[int(k) for k in input().split()]
  x=s[0]
  y=s[1]
  c=s[2]
  p=a[x-1]+b[y-1]-c
  if p<=z:
    z=p 
  m=m+1
print(z)

Solution (Python):
A,B,M = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]
B_list = [int(y) for y in input().split()]
discount = []
min = 10000000
for _ in range(M):
  case = [int(x) for x in input().split()]
  discount.append(case)

min_a = sorted(A_list)[0]
min_b = sorted(B_list)[0]
 
for i in range(M):
  temp = A_list[discount[i][0]-1] + B_list[discount[i][1]-1] - discount[i][2]
  if temp < min:
    min = temp
    
if min_a + min_b > min:
  print(min)
else:
  print(min_a + min_b)

Solution (Python):
a, b, m = list(map(int, input().split()))

pa = [int(p) for p in input().split()]
pb = [int(p) for p in input().split()]

pc = []

for c in range(m):
  x, y, d = list(map(int, input().split()))
  pc.append(pa[x-1]+pb[y-1]-d)
  
min_c = min(pc)
if min_c<0:
  min_c=0
min_ab = min(pa)+min(pb)

if min_c < min_ab:
  print(min_c)
else:
  print(min_ab)

Solution (Python):

a_n, b_n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [input().split() for i in range(m)]


min_price = min(a) + min(b)
for p in x:
   tmp_price = int(a[int(p[0])-1]) + int(b[int(p[1])-1]) - int(p[2])
   if tmp_price < min_price:
       min_price = tmp_price
print(min_price)

Solution (Python):


A,B,M = [int(i) for i in input().rstrip().split()]
a_list = [int(i) for i in input().rstrip().split()]
b_list = [int(i) for i in input().rstrip().split()]
xyc_list = [list(map(int, input().rstrip().split())) for i in range(M)]


min_price = min(a_list) + min(b_list)

for x,y,c in xyc_list:
    price_discount = a_list[x-1] + b_list[y-1] - c
    min_price = min( min_price, price_discount)

print(min_price)

Solution (Python):
A, B, M = map(int, input().split())
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
c = {}
m = 2000000
for i in range(M):
    x, y, c2 = map(int, input().split())
    c[(x, y)] = c2
    value = a[x-1] + b[y-1] - c2
    if m > value:
        m = value

if (min(a), min(b)) in c:
    print(m)
else:
    if m > min(a) + min(b):
        print(min(a) + min(b))
    else:
        print(m)

Solution (Python):
line1 = input().split()
price_a = input().split()
price_b = input().split()
min_a = int(min(price_a))
min_b = int(min(price_b))
n = int(line1[2])
candidate = [min_a+min_b]
for i in range(n):
  discount_data = input().split()
  target_a = int(discount_data[0])
  target_b = int(discount_data[1])
  discount = int(discount_data[2])
  total = int(price_a[target_a -1]) + int(price_b[target_b -1]) -discount
  candidate.append(total)
print(min(candidate))

Solution (Python):
A , B , M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [min(a) + min(b)]
for i in range(M):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print(min(ans))

Solution (Python):
a, b, m = map(int,input().split())

ai = list(map(int,input().split()))
bi = list(map(int,input().split()))

min_b = min(bi)
min_a = min(ai)

price = float('inf')
for i in range(m):
  mi = list(map(int,input().split()))
  if price > ai[mi[0]-1] + bi[mi[1]-1] -mi[2]:
  	price = ai[mi[0]-1] + bi[mi[1]-1] -mi[2]

if price < min_a + min_b:
  print(price)
else:
  print(min_a + min_b)

Solution (Python):
A,B,M = (int(x) for x in input().split())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
min_yen = min(a_list)+min(b_list)
m_list = []
for i in range((M)):
    m = [int(x) for x in input().split()]
    a = a_list[m[0]-1]
    b = b_list[m[1]-1]
    m = m[2]
    coupon_used = (a+b)-m
    min_yen = min(min_yen,coupon_used)    

print(min_yen)

Solution (Python):
a,b,m = map(int,input().split())
i = list(map(int,input().split()))
j = list(map(int,input().split()))
v = []
for k in range(m):
  x,y,c = map(int,input().split())
  v.append(i[x-1]+j[y-1]-c)
v.append(min(i)+min(j))
print(min(v))

Solution (Python):
abm = input().split()

xyc = [0]*int(abm[2])

aa = input().split()
bb = input().split()
mi = [0]*int(abm[2])

for i in range(0,int(abm[2])):
  xyc[i] = input().split()

for i in range(0,int(abm[2])):
  x = int(xyc[i][0]) - 1
  y = int(xyc[i][1]) - 1
  c = int(xyc[i][2])
  mi[i] = int(aa[x]) + int(bb[y]) - c

ab = 0
aa =  [int(s) for s in aa]
bb =  [int(s) for s in bb]
ab = min(aa) + min(bb)
mi.append(ab)
print(min(mi))

Solution (Python):
a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)
ans = min(a) + min(b)
for j in range(m):
    kk = a[x[j]-1] + b[y[j]-1] - c[j]
    if ans > kk:
        ans = kk
print(ans)

Solution (Python):

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = sorted(a)
b1 = sorted(b)
z = [list(map(int, input().split())) for _ in range(M)]

num1 = a1[0] + b1[0]

for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    if num < num1:
        num1 = num
print(num1)

Solution (Python):
a, b, c = list(map(int,input().split()))
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = [list(map(int,input().split())) for i in range(c)]
ans = 0

for i in range(c):
  ans1 = aa[cc[i][0] - 1] + bb[cc[i][1] - 1] - cc[i][2]
  if i == 0 :
    ans = ans1
  ans = min(ans,ans1)

aa.sort()
bb.sort()
ans2 = aa[0] + bb[0]
ans = min(ans, ans2)
  
print(ans)

Solution (Python):
A, B, M = map(int, input().split())
rfg = [int(i) for i in input().split()]
mcw = [int(i) for i in input().split()]
discount = [list(map(int, input().split())) for i in range(M)]

min_price = 10 ** 10

for ticket in discount:
    tmp = rfg[ticket[0]-1] + mcw[ticket[1]-1] - ticket[2]
    if tmp < min_price:
        min_price = tmp




rrfg = sorted(rfg)
mmcw = sorted(mcw)

is_true = False
for i in range(A):
    for j in range(i, B):
        tmp = rrfg[i] + mmcw[j]
        if tmp >= min_price:
            break
        else:
            min_price = tmp
            is_true = True
            break

    if is_true:
        break

print(min_price)

Solution (Python):
A,B,M=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
coupon=[list(map(int,input().split())) for i in range(M)]
mini=2*(10**5)
for j in range(M):
    p_a=coupon[j][0]
    p_b=coupon[j][1]
    p_c=coupon[j][2]
    ans=aa[p_a-1]+bb[p_b-1]-p_c
    if ans<mini:
            mini=ans
mosi=min(aa)+min(bb)
if mosi<mini:
    mini=mosi

print(mini)

Solution (Python):
s = list(map(int, input().split(" ")))

a = s[0]
b = s[1]
m = s[2]

a_l = list(map(int, input().split(" ")))
b_l = list(map(int, input().split(" ")))

ans = min(a_l) + min(b_l)

for i in range(m):
    x = list(map(int, input().split(" ")))
    if ans > (a_l[x[0] - 1] + b_l[x[1] -1] - x[2]):
        ans = a_l[x[0] -1] + b_l[x[1] -1] - x[2]


print(ans)

Solution (Python):
A, B, M = map(int, input().split())

ref = list(map(int, input().split()))
mic = list(map(int, input().split()))

price = min(ref)+min(mic)

for i in range(M):
    arg = list(map(int, input().split()))
    val = ref[arg[0]-1]+mic[arg[1]-1]-arg[2]
    if price > val:
        price = val

print(price)

Solution (Python):
A,B,M=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
mi=min(a)+min(b)
for i in range(0,M):
  Data=list(map(int, input().split()))
  wari=a[Data[0]-1]+b[Data[1]-1]-Data[2]
  if(mi>wari):
    mi=wari
print(mi)

Solution (Python):

A, B, M = map(int,  input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

sum = []
for i in range(M):
        x, y, c = map(int,  input().split())
        sum.append(a[x-1]  + b[y-1] - c)

a.sort()
b.sort()

sum.append(a[0] + b [0])

sum.sort()

i=0
while sum[i] < 0:
        i+=0
print(sum[i])

Solution (Python):
a,b,m=(int(x) for x in input().split())
a_list=[int(x) for x in input().split()]
b_list=[int(x) for x in input().split()]

min_price=min(a_list)+min(b_list)

for count in range(m):
    x,y,c=(int(x) for x in input().split())
    discount_price=a_list[x-1]+b_list[y-1]-c
    if discount_price<min_price:
        min_price=discount_price
    else:
        continue
print(min_price)

Solution (Python):
A, B, M = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

miniC = min(a) + min(b)

for i in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    miniC = min(miniC, a[x] + b[y] - c)

print(miniC)

Solution (Python):
a, b, m = map(int, input().split())
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = min(ref) + min(micro)

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print(min(mini, amount))