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):
a, b, m = input().split(" ")
rei_list = []
den_list = []
war_list = []
rei_list = list(map(int,input().split(" ")))
den_list = list(map(int,input().split(" ")))

for i in range(int(m)):
    kar = list(map(int,input().split(" ")))
    war_list.append(kar)

ned_list=[]
ned_list.append(min(rei_list)+min(den_list))

for i in range(int(m)):
    x = war_list[i][0]
    y = war_list[i][1]
    z = war_list[i][2]
    ned_list.append(rei_list[x-1] + den_list[y-1] - z)
    
print(min(ned_list))

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

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

print(min(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 = []

ans = min(A) + min(B)
for i in range(m):
    x, y, c = map(int, input().split())
    if A[x-1] + B[y-1] - c < ans:
        ans = A[x-1] + B[y-1] - c
print(ans)

Solution (Python):
a, b, m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
minu = min(al) + min(bl)
for i in range(m):
    an, bn, wari = map(int, input().split())
    if minu > (al[an -1] + bl[bn -1] - wari):
        minu = (al[an -1] + bl[bn -1] - wari)
print(minu)

Solution (Python):
def main():
    A, B, M = map(int, input().split())
    xyc_list = [0]*M

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

    mini = min(a_list)+min(a_list)
    for x, y, c in xyc_list:
        value = a_list[x-1] + b_list[y-1] - c
        if value < mini:
            mini = value
    print(mini)


if __name__ == '__main__':
    main()

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 _ in range(M):
  a, b, c = map(int, input().split())
  total = A[a-1]+B[b-1]-c
  ans = min(ans, total)
print(ans)

Solution (Python):
A, B, M = [int(num) for num in input().split()]
a = [int(num) for num in input().split()]
b =  [int(num) for num in input().split()]
minimum = -1
for i in range(M):
    xi, yi, ci =  [int(num) for num in input().split()]
    ai = a[xi-1]
    bi = b[yi-1]
    sum = ai + bi - ci
    if minimum == -1 or sum < minimum:
        minimum = sum
a.sort()
b.sort()
sum = a[0]+b[0]
if minimum < sum:
    print(minimum)
else:
    print(sum)

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):
    X, Y, C = map(int, input().split())
    if(ans > a[X-1]+b[Y-1]-C):
        ans = a[X-1]+b[Y-1]-C

print(ans)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [tuple(map(int, input().split())) for _ in range(M)]

minP = min(a) + min(b)
for x, y, c in xyc:
    minP = min(a[x-1]+b[y-1]-c, minP)
print(minP)

Solution (Python):
a, b, m = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
k = []
notDisc = min(As) + min(Bs)
k.append(notDisc)
for i in range(m):
    t1,t2,t3 = map(int, input().split())
    dis = As[t1-1] + Bs[t2-1] - t3
    k.append(dis)
print(min(k))

Solution (Python):
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = []
for i in range(M):
    m_list.append(list(map(int, input().split())))

ans = min(a_list) + min(b_list)
for i in range(len(m_list)):
    price = a_list[m_list[i][0]-1] + b_list[m_list[i][1]-1] - m_list[i][2]
    ans = min(ans,price)

print(ans)

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

a_list =list(map(int,input().split()))
b_list =list(map(int,input().split()))
m_list =[list(map(int,input().split())) for _ in range(m)]


mini = min(a_list) + min(b_list)
for i in range(m):
  ai = m_list[i][0] - 1
  bi = m_list[i][1] - 1
  ci = m_list[i][2]

  temp = a_list[ai] + b_list[bi] - ci

  if temp < mini:
    mini = temp
print(mini)

Solution (Python):



Anum, Bnum, Mnum = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = []
for _ in range(Mnum):
    M.append(list(map(int, input().split())))
    

ans = min(A)+min(B)
for x, y, c in M:
    cost = A[x-1]+B[y-1]-c
    if cost < ans:
        ans = cost


print(ans)

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):
    x,y,c=map(int,input().split())
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Solution (Python):
a,b,m = map(int, input().split())
f = list(map(int, input().split()))
g = list(map(int, input().split()))
ans = min(f) + min(g)
for _ in range(m):
  x,y,c = map(int, input().split())
  t = f[x-1] + g[y-1] - c
  if ans > t: ans = t
print(ans)

Solution (Python):
a,b,m=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
x=[ list(map(int,input().split())) for i in range(m)]
hantei=1000000000000
for i in range(m):
  if hantei>=(aa[x[i][0]-1]+bb[x[i][1]-1]-x[i][2]):
    hantei=(aa[x[i][0]-1]+bb[x[i][1]-1]-x[i][2])
if hantei>=min(aa)+min(bb):
  hantei=min(aa)+min(bb)
print(hantei)

Solution (Python):
a,b,m=map(int,input().split())
af=list(map(int,input().split()))
bf=list(map(int,input().split()))
almin=sorted(af)
blmin=sorted(bf)
nmin=almin[0]+blmin[0]
bmin=blmin[0]
for i in range(m):
  x,y,c=map(int,input().split())
  k=af[x-1]+bf[y-1]-c
  if k<nmin:
    nmin=k
print(nmin)

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

a_ary = list(map(int, input().split()))
b_ary = list(map(int, input().split()))
waribiki = []
for i in range(m):
    waribiki.append(list(map(int, input().split())))

min_cost = min(a_ary) + min(b_ary)

for i in range(m):
    tmp = a_ary[waribiki[i][0]-1] + b_ary[waribiki[i][1]-1] - waribiki[i][2]
    if tmp < min_cost:
        min_cost = tmp
print(min_cost)

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

from collections import defaultdict

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

MINB = min(b)

wari = defaultdict(list)
for _ in range(M):
    x,y,c = map(int,input().split())
    wari[x-1].append((y-1,c))

ans = float("inf")
for i in range(A):
    tmp = a[i] + MINB
    for y,c in wari[i]:
        tmp = min(tmp, a[i] + b[y] - c)
    ans = min(ans, tmp)

print(ans)

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):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x - 1] + B[y - 1] - c)
print(ans)

Solution (Python):
A, B, M = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
ans = min(list_A) + min(list_B)


for i in range(M):
    tmp_list = list(map(int, input().split()))
    tmp_cost = list_A[tmp_list[0]-1] + list_B[tmp_list[1]-1] - tmp_list[2]
    ans = min(tmp_cost, ans)

print(ans)

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

minnum = min(a_list) + min(b_list)

for i in range(m):
    x,y,c = list(map(int,input().split()))
    if minnum > a_list[x-1] + b_list[y-1] - c:
        minnum = a_list[x-1] + b_list[y-1] - c

print(minnum)

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

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

price_min = min(a) + min(b)


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

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

min_a = 10**5
for i in range(A):
    if min_a > a[i]:
        min_a = a[i]

min_b = 10**5
for i in range(B):
    if min_b > b[i]:
        min_b = b[i]

min = min_a + min_b


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

print(min)

Solution (Python):

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

tmp_min = min(a)+min(b)

for i in range(M):
    tmp = a[x[i][0]-1]+b[x[i][1]-1] - x[i][2]
    if tmp < tmp_min:
        tmp_min = tmp
    else:
        pass

print(tmp_min)

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()]

x_list = []
y_list = []
c_list = []

for s in range(m):
  x,y,c = (int(value) for value in input().split())
  x_list.append(x)
  y_list.append(y)
  c_list.append(c)

min_value = min(a_list) + min(b_list)

for i in range(len(x_list)):
  value = a_list[x_list[i]-1] + b_list[y_list[i]-1] - c_list[i]
  if value < min_value:
    min_value = value
print(min_value)

Solution (Python):
a,b,m = map(int, input().split(' '))
a_ = list(map(int, input().split(' ')))
b_ = list(map(int, input().split(' ')))
res = min(a_) + min(b_)
for i in range(m):
    x,y,c = map(int, input().split(' '))
    z = a_[x-1] + b_[y-1] - c
    if res > z:
        res = z
print(res)

Solution (Python):
info = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
num = -1
for i in range(info[2]):
    temp = [int(i) for i in input().split()]
    price = a[temp[0]-1]+b[temp[1]-1]-temp[2]
    if (num == -1 or num > price):
        num = price
if min(a)+min(b) < num:
    num = min(a)+min(b)
print(num)

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()]
res = min(A) + min(B)
for j in range(m):
    x, y, c = map(int, input().split())
    summ = A[x-1] + B[y-1] - c
    if summ < res:
        res = summ

print(res)

Solution (Python):
a_len, b_len, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ds = [[int(i) for i in input().split()] for _ in range(m)]

min = min(a) + min(b)
for x, y, c in ds:
    price = a[x-1] + b[y-1] - c
    if price < min:
        min = price

print(min)

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

As = [int(x) for x in input().rstrip().split()]
Bs = [int(x) for x in input().rstrip().split()]

min_val = min(As) + min(Bs)

for i in range(M):
    x, y, c = map(int, input().rstrip().split())
    val = As[x-1] + Bs[y-1] - c
    if min_val > val:
        min_val = val
print(min_val)

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):
  x = list(map(int, input().split()))
  m.append(x)
a_min = min(a)
b_min = min(b)
s_min = a_min + b_min
for i in range(M):
  if a[m[i][0]-1] + b[m[i][1]-1] - m[i][2] < s_min:
    s_min = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2]
print(s_min)

Solution (Python):
A, B, M = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]

m = []
for i in range(M):
    m.append([int(v) for v in input().split()])

a_min = min(a)
b_min = min(b)
s_min = a_min + b_min

for w in m:
    ai, bi, ci = w
    tmp_min = a[ai-1] + b[bi-1] - ci
    if tmp_min < s_min:
        s_min = tmp_min
        
print(s_min)

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

xyc = []
for i in range(M):
    xyci = map(int, raw_input().split())
    xyc.append(xyci)

a_min = min(a)
b_min = min(b)

ans = a_min + b_min

for i in range(M):
    xi = xyc[i][0]-1
    yi = xyc[i][1]-1
    ci = xyc[i][2]

    cost = a[xi]+ b[yi] -ci
    ans = min(ans, cost)

print ans

Solution (Python):
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(m)]

l = sorted(A)[0]+sorted(B)[0]
for d in D:
    l = min(l, A[d[0]-1]+B[d[1]-1]-d[2])
print(l)

Solution (Python):
A,B,M=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().split()]
a_min=min(a)
b_min=min(b)

ans=a_min+b_min
for i in range(M):
    x,y,c=[int(x) for x in input().rstrip().split()]
    now=a[x-1]+b[y-1]-c
    if now<ans:
        ans=now
print(ans)

Solution (Python):

import sys
import math
import numpy as np
import itertools


a, b, m = (int(i) for i in input().split())  

aprice = [int(i) for i in input().split()] 
bprice = [int(i) for i in input().split()] 
c = [[int(i) for i in input().split()] for i in range(m)] 

amin=999999
for i in range(a):
    amin = min(amin,aprice[i])
bmin=999999
for i in range(b):
    bmin = min(bmin,bprice[i])

p=[]
for i in range(m):

    p.append(aprice[c[i][0]-1]+bprice[c[i][1]-1]-c[i][2])

answer = amin+bmin
for i in p:
    answer = min(answer, i) 

print(answer)

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())

a_m=min(a)
b_m=min(b)

ans=(a_m+b_m)
tem=0

for i in range(M):
    aa=x[i]-1
    bb=y[i]-1
    hikaku=a[aa]+b[bb]-c[i]
    ans=min(ans,hikaku)


print(ans)

Solution (Python):
a, b, m = map(int, input().split())
arr1 = [int(j) for j in input().split()]
arr2 = [int(j) for j in input().split()]

pfx1 = []
pfx2 = []

su = 0
for i in range(a):
	su += arr1[i]
	pfx1 += [su]
su = 0
for i in range(b):
	su += arr2[i]
	pfx2 += [su]

mi = 9999999999999
k1 = min(arr1)
k2 = min(arr2)
for i in range(m):
	x, y, c = map(int, input().split())
	mi = min(mi, arr1[x-1]+arr2[y-1]-c, k1+k2)
print(mi)

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


cheapest = min(a) + min(b)
for i in m:
  price = a[i[0]-1] + b[i[1]-1] - i[2]
  if price < cheapest: cheapest = price
print(cheapest)

Solution (Python):
A, B, M = [int(x) for x in input().split()]
list_a = [int(x) for x in input().split()]
list_b = [int(x) for x in input().split()]

list_x = [0] * M
list_y = [0] * M
list_c = [0] * M

for i in range(M):
    list_x[i], list_y[i], list_c[i] = \
        [int(x) for x in input().split()]




min_ab = min(list_a) + min(list_b)

for i in range(M):
    min_ab = min(min_ab, list_a[list_x[i]-1] + list_b[list_y[i]-1] - list_c[i])

print(min_ab)

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

min_cost = min(a) + min(b)

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

print(min_cost)

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

ans = sorted(a)[0] + sorted(b)[0] 

for i in range(M):
    price = a[MList[i][0]-1] + b[MList[i][1]-1] - MList[i][2]
    if (ans > price):
        ans = price

print(ans)

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

Solution (Python):
def main(A,B,p):
    mina = min(A)
    minb = min(B)
    res = mina + minb
    for i in range(len(p)):
        x = A[p[i][0]-1]
        y = B[p[i][1]-1]
        val = x+y-p[i][2]
        if val < res:
            res = val
    return res

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 _ in range(m)]
print(main(A,B,p))

Solution (Python):
[A, B, M]    = list(map(int, input().split()))
lst_a        = list(map(int, input().split()))
lst_b        = list(map(int, input().split()))
lst_discount = [list(map(int, input().split())) for i in range(M)]

def main(lst_a, lst_b, lst_discount):

    lst_price = [min(lst_a) + min(lst_b)]

    for discount in lst_discount:
        reizouko = lst_a[discount[0] - 1]
        renji    = lst_b[discount[1] - 1]
        lst_price.append(reizouko + renji - discount[2])
    
    return min(lst_price)


if __name__ == "__main__":

    answer = main(lst_a, lst_b, lst_discount)
    print(answer)

Solution (Python):


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


x=min(a)+min(b)

for i in d:
    t=a[i[0]-1]+b[i[1]-1]-i[2]
    if t<x:
        x=t
print(x)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

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

disc.sort()
min_ab = min(a) + min(b)

if disc[0] <= min_ab:
    print(disc[0])
else:
    print(min_ab)

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

Solution (Python):
A,B,M = list(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):
    x, y, c = list(map(int,input().split()))
    tmp = a[x-1] + b[y-1] - c
    ans = min(tmp,ans)
print(ans)

Solution (Python):
A, B, M = [int(i) for i in input().split(' ')]
A_list = [int(i) for i in input().split(' ')]
B_list = [int(i) for i in input().split(' ')]

min_val = min(A_list) + min(B_list)
for k in range(M):
    x,y,c = [int(i) for i in input().split(' ')]
    tmp = A_list[x-1] + B_list[y-1] - c
    if tmp < min_val:
        min_val = tmp
if min_val < tmp:
    print(min_val)
else:
    print(tmp)

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()]

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

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

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()]
l=[min(a)+min(b)]
for i in range(M):
   x,y,c=map(int,input().split())
   x-=1
   y-=1
   l.append(a[x]+b[y]-c)
print(min(l))

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)]
xyc.sort(key=lambda x:(x[0], x[1], x[2]))
ans=min(a)+min(b)

for i in range(M):
    x, y, c = xyc[i]
    ans=min(ans, a[x-1]+b[y-1]-c)
print(ans)

Solution (Python):
from sys import stdin
import math

a, b, m = [int(x) for x in stdin.readline().rstrip().split()]
aa = [int(x) for x in stdin.readline().rstrip().split()]
bb = [int(x) for x in stdin.readline().rstrip().split()]

result = min(aa) + min(bb)

for i in range(m):
    x, y, c = [int(x) for x in stdin.readline().rstrip().split()]
    temp = aa[x-1] + bb[y-1] - c
    if temp < result:
        result = temp

print(result)

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

mincost = 10**12
for _ in range(M):
	x, y, c = [int(i) for i in input().split()]
	cost = a[x-1] + b[y-1] - c
	if cost < mincost:
		mincost = cost
nodiscount_cost = min(a) + min(b)
if nodiscount_cost < mincost:
	print(nodiscount_cost)
else:
	print(mincost)

Solution (Python):

a, b, m = map(int, input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
xyc = [tuple(map(int, input().split())) for _ in range(m)]

amin = min(a)
bmin = min(b)
ans = amin + bmin
for x, y, c in xyc:
    ans = min(a[x-1] + b[y-1] - c, ans)
print(ans)

Solution (Python):
def main():

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

    a_min, b_min = min(a), min(b)
    val_min = a_min + b_min

    for i in range(M):
        val = a[dis[i][0] - 1] + b[dis[i][1] - 1] - dis[i][2]
        if val < val_min:
            val_min = val

    print(val_min)


if __name__ == '__main__':
    main()

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)]

price = min(A)+min(B)
for x,y,c in xyc:
    k = A[x-1] + B[y-1] - c 
    if k < price:
        price = k
        
print(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 i in range(M)]


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

Solution (Python):
import sys
from collections import deque


def input():
    return sys.stdin.readline()[:-1]


def solve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a_min = min(a)
    b_min = min(b)
    memo = [0]*(M+1)
    memo[0] = a_min + b_min
    for m in range(M):
        x, y, c = map(int, input().split())
        memo[m+1] = a[x-1]+b[y-1]-c
    print(min(memo))


if __name__ == "__main__":
    solve()

Solution (Python):
a,b,m = map(int,input().split())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_x = []
for i in range(m):
  l_x.append(list(map(int,input().split())))


sonomama = min(l_a)+min(l_b)


l_warine = [sonomama]
for i in l_x:
  l_warine.append( l_a[ i[0]-1 ] + l_b[ i[1]-1 ] -i[2] )
print(min(l_warine))

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

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

an=min(ali)+min(bli)

for i in range(m):
    x,y,c=map(int,input().split())
    if an>((ali[x-1]+bli[y-1])-c):
        an=((ali[x-1]+bli[y-1])-c)

print(an)

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

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

mini = min(a_list) + min(b_list)

c_list = []

for i in range(m):
  a_1, b_1, m_1 = map(int, input().split())
  c_list.append(a_list[a_1 - 1] + b_list[b_1 - 1] - m_1)

c_list.append(mini)

ans = min(c_list)

print(ans)

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 set(range(M)):
    x,y,c = map(int, input().split())
    ans = min(ans,a[x-1]+b[y-1]-c)
print(ans)

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

refrigerator = list(map(int, input().split()))
microwave = list(map(int, input().split()))



min_price = min(refrigerator) + min(microwave)

for i in range(m):
    x, y, c = list(map(int, input().split()))
    min_price = min(min_price, refrigerator[x-1]+microwave[y-1]-c)
    
print(min_price)

Solution (Python):
A,B,M = list(map(int,input().split()))
listA = list(map(int,input().split()))
listB = list(map(int,input().split()))
listC = set([])
for i in range(M):
    M = list(map(int,input().split()))
    listC.add(listA[M[0]-1]+listB[M[1]-1]-M[2])
D = min(listC)
E = min(listA) + min(listB)
print(min(D,E))

Solution (Python):
a,b,m = map(int,input().split())
aprice = list(map(int,input().split()))
bprice = list(map(int,input().split()))
waribiki = [list(map(int, input().split())) for i in range(m)]
minprice = min(aprice)+min(bprice)
for i in range(len(waribiki)):
         tmp = aprice[waribiki[i][0]-1]+bprice[waribiki[i][1]-1]-waribiki[i][2]
         if minprice > tmp:
                  minprice = tmp
print(minprice)

Solution (Python):
import numpy as np
import fractions

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 k in range(m):
    i,j,x=map(int, input().split())
    ans=min(ans,A[i-1]+B[j-1]-x)
if(ans<0):ans=0
print(ans)

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 _ in range(M):
    tmp = list(map(int,input().split()))
    x.append(tmp[0])
    y.append(tmp[1])
    c.append(tmp[2])

ans = min(a) + min(b)

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

print(ans)

Solution (Python):
f = lambda:map(int,input().split())
a,b,m = f()
la = list(f())
lb = list(f())
lx,ly,lc = [],[],[]
a = min(la)+min(lb)
for _ in range(m):
  x,y,c = f()
  a = min(a,la[x-1]+lb[y-1]-c)
print(a)

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

al = list(map(int, input().split()))
bl = list(map(int, input().split()))
xl = list(list(map(int, input().split())) for _ in range(m))

cost = min(al) +min(bl)
for i in range(m):
    ai = xl[i][0]
    bi = xl[i][1]
    ci = xl[i][2]
    if cost > (al[ai-1] + bl[bi-1] - ci):
        cost = (al[ai-1] + bl[bi-1] - ci)

print(cost)

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 _ in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x-1] + B[y-1] - c)

print(ans)

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

ans = sorted(a)[0]+sorted(b)[0]
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
    if a[x[i]-1] + b[y[i]-1] - c[i] < ans:
        ans = a[x[i]-1] + b[y[i]-1] - c[i]



print(ans)

Solution (Python):
A,B,M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
for _ in range(M):
    tmp = [int(x) for x in input().split()]
    c.append(tmp)

ans = min(a)+min(b)
for x in c:
    ans = min((a[x[0]-1]+b[x[1]-1]-x[2]),ans)

print(ans)

Solution (Python):
import sys
from pprint import pprint

A, B, M = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))
b = list(map(int, sys.stdin.readline().strip().split()))

ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, sys.stdin.readline().strip().split())
    ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

Solution (Python):
A, B, M = [int(s) for s in input().split()]
Alist = [int(s) for s in input().split()]
Blist = [int(s) for s in input().split()]
minimum = min(Alist) + min(Blist)
for i in range(M):
  xi, yi, c = [int(s) for s in input().split()]
  xi = xi-1
  yi = yi-1
  attempt = Alist[xi] + Blist[yi] - c
  if minimum >= attempt:
    minimum = attempt
print(minimum)

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

Solution (Python):
a,b,m = [int(x) for x in input().split()]
lia = [int(x) for x in input().split()]
lib = [int(x) for x in input().split()]
wari = list()
for _ in range(m):
    wari.append([int(x) for x in input().split()])
ans = 10**20
for i in wari:
    s = lia[i[0]-1]+lib[i[1]-1]-i[2]
    ans = min(ans,s)
x = min(lia)+min(lib)
ans = min(ans,x)
print(ans)

Solution (Python):
A_num,B_num,M_num = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Waribiki = []
for _ in range(M_num):
    Waribiki.append(list(map(int,input().split())))

min_price = min(A) + min(B)

for w in Waribiki:
    x = w[0]
    y = w[1]
    c = w[2]
    min_price = min(min_price, A[x-1]+B[y-1]-c)
print(min_price)

Solution (Python):
A, B, M = map(int, input().split())
As = [i for i in map(int, input().split())]
Bs = [i for i in map(int, input().split())]
out = min(As) + min(Bs)
for _ in range(M):
  x, y, c = map(int, input().split())
  out = min(out, As[x-1]+Bs[y-1]-c)
print(out)

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

result = min(a) + min(b)
for i in range(M):
    x,y,c = xyc[i]
    cost = a[x-1] + b[y-1] - c
    result = min(result, cost)
print(result)

Solution (Python):
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
info=[]
for i in range(m):
    x,y,c=map(int,input().split())
    info.append([x-1,y-1,c])
ans=min(a)+min(b)
for i in range(m):
    p=a[info[i][0]]+b[info[i][1]]-info[i][2]
    if p<ans:
        ans=p
print(ans)

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

min_tmp = min(a)+min(b)

for i in range(M):
  x,y,c = list(map(int,input().split()))
  tmp = a[x-1]+ b[y-1]-c
  if min_tmp > tmp:
    min_tmp = tmp

print(min_tmp)