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 = [int(n) for n in input().split()]
a  = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
ma = sorted(a)[0]
mb = sorted(b)[0]
XY = {}
ans = ma + mb
for m in range(M):
    x, y, c = [int(n) for n in input().split()]
    dv = a[x-1] + b[y-1] - c
    ans = min(ans , dv)
print(ans)

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

disc = [list(map(int, input().split())) for i in range(m)]
import numpy as np


from collections import deque
ans = []

ans = deque(ans)

for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)

print(min( min(ans), min(a1)+min(b1) ))

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

Solution (Python):
A, B, M = [int(n) for n in input().split()]
a  = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
ma = sorted(a)[0]
mb = sorted(b)[0]
XY = {}
ans = ma + mb
for m in range(M):
    x, y, c = [int(n) for n in input().split()]
    dv = a[x-1] + b[y-1] - c
    mv = min((ma+mb), dv)
    if ans > mv:
        ans = mv
print(ans)

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

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

Solution (Python):
import numpy as np
A, B, M = list(map(int,input().split()))
a = np.array(list(map(int,input().split())))
b = np.array(list(map(int,input().split())))

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

x = np.array(x)
min_val = a.min() + b.min()

for i in range(len(x)) :
    if min_val > a[x[i][0]-1] + b[x[i][1]-1] - x[i][2] :
        min_val = a[x[i][0]-1] + b[x[i][1]-1] - x[i][2]

print(min_val)

Solution (Python):



x, y, m = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
num = [min(a)+min(b)]

for _ in range(m):
    tmp = [int(i) for i in input().split()]
    num.append(a[tmp[0]-1]+b[tmp[1]-1]-tmp[2])

print(min(num))

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

reizou = input()
reizou_list = reizou.split()

renji = input()
renji_list = renji.split()
cupon_list = []

price = int(min(reizou_list)) + int(min(renji_list))

for i in range(int(M)):
    
    
    
    
    a,b,c = map(int,input().split())
    price_coupon = int(reizou_list[int(a) - 1]) + int(renji_list[int(b) - 1]) - int(c)
    if price > price_coupon: price = price_coupon

print(price)

Solution (Python):
import sys
input = sys.stdin.readline
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):
	sum = 0
	x,y,c = map(int,input().split())
	sum = a[x-1] + b[y-1] - c
	ans = min(ans,sum)
print(ans)

Solution (Python):
"""
B
"""
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=float("inf")
for x,y,c in xyc:
    ans=min(ans,a[x-1]+b[y-1]-c)
ans=min(ans,min(a)+min(b))
print(ans)

Solution (Python):
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()

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

Solution (Python):
A, B, M = [int(x) for x in input().split()]
Aprices = [int(x) for x in input().split()]
Bprices = [int(x) for x in input().split()]
mins = min(Aprices) + min(Bprices)
for i in range(M):
    a, b, c = [int(x) for x in input().split()]
    current = Aprices[a -1] + Bprices[b - 1] - c
    mins = min(mins, current)

print(mins)

Solution (Python):
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''
p = 10 ** 9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
'''




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


ans = 10**19
for i in range(m):
    now = a[ms[i][0]-1] + b[ms[i][1]-1] - ms[i][2]
    if(ans > now):
        ans = now
   
mina = min(a)
minb = min(b)
if(mina+minb < ans):
    ans = mina+minb
print(ans)

Solution (Python):
A, B, M = map(int, raw_input().split())
a_s = map(int, raw_input().split())
b_s = map(int, raw_input().split())
w = [[0] * B] * A
cost = 10 ** 30
for _ in xrange(M):
    x, y, c = map(int, raw_input().split())
    cost = min(cost, a_s[x-1] + b_s[y-1] - c)
    w[x-1][y-1] = max(w[x-1][y-1], c)

a_s = sorted(enumerate(a_s), key=lambda t: t[1])
b_s = sorted(enumerate(b_s), key=lambda t: t[1])
for i, a in a_s:
    if a + b_s[0][1] >= cost:
        break
    for j, b in b_s:
        if w[i][j] > 0:
            break
        cost = min(cost, a + b)

print cost

Solution (Python):
a, b, m = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
m1 = min(A) + min(B)
m2 = 1000000
for i in range(m):
    l = list(map(int, input().split(' ')))
    lp = A[l[0] - 1] + B[l[1] - 1] - l[2]
    if lp < m2:
        m2 = lp        
print(m1 if m1 < m2 else m2)

Solution (Python):
import sys
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a) + min(b)
w = [list(map(int,input().split())) for i in range(M)]
for i in range(M):
    if a[w[i][0]-1] + b[w[i][1]-1] - w[i][2] < ans:
        ans = a[w[i][0]-1] + b[w[i][1]-1] - w[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()))
dis=[list(map(int,input().split()))  for l in range(M)]

comp1=a[dis[0][0]-1]+b[dis[0][1]-1]-dis[0][2]
for l in range(M):
    y=a[dis[l][0]-1]+b[(dis[l][1])-1]-dis[l][2]
    if comp1>y:
        comp1=y

comp2=min(a)+min(b)
                  
print(min(comp1,comp2))

Solution (Python):
x = list(map(int,input().split(" ")))
a = x[0]
b = x[1]
m = x[2]
a_list = list(map(int,input().split(" ")))
b_list = list(map(int,input().split(" ")))
x_list =[]
money_list = []
for i in range(m):
    xi_list = []
for i in range(m):
    xi = list(map(int,input().split(" ")))
    x_list.append(xi)
    money = a_list[xi[0]-1]+b_list[xi[1]-1]-xi[2]
    money_list.append(money)
    
money_list.append(min(a_list)+min(b_list))

print(min(money_list))

Solution (Python):
s = input().split(' ')
n = 0
if int(s[0]) > 0:
    n += 1
if int(s[1]) > 0:
    n += 1
if int(s[2]) > 0:
    n += int(s[2])
coupon = []
for times in range(1, n+1):
    if times == 1:
        ref = input().split(' ')
    if times == 2:
        micro = input().split(' ')
    if times > 2:
        coupon.append(input().split(' '))
price = int(ref[0]) + int(micro[0])
minPrice = price
for discount in coupon:
    price = int(ref[int(discount[0])-1]) + int(micro[int(discount[1])-1]) - int(discount[2])
    minPrice = min(minPrice, price)
ref.sort()
micro.sort()
price = int(ref[0]) + int(micro[0])
minPrice = min(minPrice, price)
print(minPrice)

Solution (Python):
x = []
y = []
z = []
x = input().split()


y = input().split() 

z = input().split() 

waribiki = []
nest = []
for i in range(int(x[2])):
    waribiki = input().split()
    nest.append(waribiki)

inu = 0
neko = 0
nedan = []
for i in range(len(nest)):
    inu = int(nest[i][0])
    neko = int(nest[i][1])
    nedan.append(int(y[inu-1])+int(z[neko-1])-int(nest[i][2]))


may = int(min(y)) + int(min(z)) 

if len(nedan) > 1:
    print(min(nedan))
elif int(may) <= min(nedan):
    print(may)
else:
    print(nedan[0])

Solution (Python):
A,B,M = map(int,input().split())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
C_list = []
for x in range(M):
    C_list.append(list(map(int,input().split())))

ans = min(A_list) + min(B_list)


for x in C_list:
    tmp = A_list[x[0]-1] + B_list[x[1]-1] - x[2]

    if(ans > tmp):
        ans = tmp
print(ans)

Solution (Python):
A, B, M = map(int, input().split())
list_a = []
list_b = []
list_x = []
list_y = []
list_c = []
sum = []

a = input()
list_a = a.split()

b = input()
list_b = b.split()

for i in range(0, M):
    x, y, c = map(int, input().split())
    list_x.append(x)
    list_y.append(y)
    list_c.append(c)

list_d = sorted(list_a)
list_e = sorted(list_b)

sum_1 = int(list_d[0]) + int(list_e[0])
sum.append(sum_1)

for k in range(0, M):
    x_1 = int(list_x[k])
    y_1 = int(list_y[k])
    sum_2 = int(list_a[x_1-1]) + int(list_b[y_1-1]) - list_c[k]
    sum.append(sum_2)

print(min(sum))

Solution (Python):
a, b, m = map(int, input().split())
a_price = list(map(int, input().split()))
b_price = list(map(int, input().split()))
m_prices = []
for i in range(m):
  m_prices.append(list(map(int, input().split())))


ref = min(a_price)
mi = min(b_price)
total_min = ref + mi


discount_prices_from_tickets = []
dis_price_temp = 0
for i in range(m):
  discount_prices_from_tickets.append(a_price[m_prices[i][0] - 1] + b_price[m_prices[i][1] - 1] - m_prices[i][2]) 
bigest_discount = min(discount_prices_from_tickets)

print(min(total_min,bigest_discount))

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

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

print(result)

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

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

s = input()
b = [int(x) for x in list(s.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())

amin = 10 ** 6
for aa in a:
    amin = min(amin,aa)
bmin = 10 ** 6
for bb in b:
    bmin = min(bmin,bb)

sum_min = amin + bmin

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

print(sum_min)

Solution (Python):
data = input().split(" ")
A = input().split(" ")
B = input().split(" ")
total = 1000000
a = 1000000
b = 1000000
j = 0
for i in data:
    data[j] = int(i)
    j += 1
j = 0
for i in A:
    A[j] = int(i)
    j += 1
j = 0
for i in B:
    B[j] = int(i)
    j += 1


for i in range(data[2]):
    data1 = input().split()
    j = 0
    for i in data1:
        data1[j] = int(i)
        j += 1
    data2 = A[data1[0]-1] + B[data1[1]-1] - data1[2]
    if total > data2:
        total = data2

for i in A:
    if a > i:
        a = i
for i in B:
    if b > i:
        b = i

if total > a+b:
    total = a+b

print(total)

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

al = input().split()
bl = input().split()
ml = [list(map(int, input().split())) for i in range(m)]

al = list(map(int, al))
bl = list(map(int, bl))

als = sorted(al)
bls = sorted(bl)

tmp = als[0] + bls[0]

comp = 0
fp = tmp
for i in ml:
  comp = al[i[0]-1] + bl[i[1]-1] - i[2]
  if comp < fp:
    fp = comp

print(fp)

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

m = []
am = min(a)
bm = min(b)

for i in range(M):
    x, y, z = map(int, input().split())

    m.append(a[x-1] + b[y-1] - z )



if am + bm > min(m):
    print(min(m))
else:
    print(am + bm)

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

Solution (Python):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = 0
Y = []
for i in range(M):
    X = list(map(int,input().split()))
    Y.append(int(a[X[0] - 1] + b[X[1] - 1] - X[2]))
Y.sort()
a.sort()
b.sort()

if Y[0] < a[0] + b[0]:
    print(Y[0])
else:
    print(a[0] + b[0])

Solution (Python):
A, B, M = map(int, input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Ms = [input().split() for i in range(M)]

no_discount_min_plice = min(As) + min(Bs)

buy_list = [no_discount_min_plice]

for i in range(0, M):
    discount_plice = As[int(Ms[i][0])-1] + Bs[int(Ms[i][1])-1] - int(Ms[i][2])
    buy_list.append(discount_plice)

print(min(buy_list))

Solution (Python):
m=list(map(int, input().split()))
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])

ans.append(min(rei)+min(den))
print(min(ans))

Solution (Python):
(A, B, M) = (int(x) for x in input().split(' '))


ai = [int(x) for x in input().split(' ')]
bj = [int(x) for x in input().split(' ')]
ck = []
for k in range(int(M)):
  ck.append([int(x) for x in input().split(' ')])

amin = min(ai)
bmin = min(bj)
abmin = amin + bmin


for cupon in ck:
  ac = ai[cupon[0]-1]
  bc = bj[cupon[1]-1]
  cost = ac + bc - cupon[2]

  if cost < abmin:
    abmin = cost

print(abmin)

Solution (Python):
(R, D, M) = list(map(int, input().split()))
R_yen = list(map(int, input().split()))
D_yen = list(map(int, input().split()))
min = 100000000
min_R = 10000000
min_D = 10000000
for i in range(M):
  (R_dis, D_dis, Dis) = list(map(int, input().split()))
  a = R_dis-1
  b = D_dis-1
  k = R_yen[a] + D_yen[b] - Dis
  if min > k:
    min = k
for i in R_yen:
  if min_R > i:
    min_R = i
for i in D_yen:
  if min_D > i:
    min_D = i
if min > min_R + min_D:
  min = min_R + min_D
print(str(min))

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

la = list(map(int, input().split()))
lb = list(map(int, input().split()))

d = []
for i in range(M):
  d.append(list(map(int, input().split())))
           
for i in range(M):
  d[i] = la[(d[i][0]-1)] + lb[(d[i][1]-1)] - d[i][2]
  
o = min(la) + min(lb)
d.append(o)

print(min(d))

Solution (Python):
import sys

lines = sys.stdin.readlines()


num_a ,num_b, num_m = [int(v) for v in lines[0].split()]


a_list = [int(v) for v in lines[1].split()[:num_a+1]]
b_list = [int(v) for v in lines[2].split()[:num_b+1]]

res1 = [
    a_list[a_i-1]+b_list[b_i-1]-discount for a_i, b_i, discount in [
        map(int, l.split())  for l in lines[3:num_m+3]
    ]
]

res2 = min(a_list) + min (b_list)

print(min(min(res1), res2))

Solution (Python):
import math

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

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

cur_best = min(a_list) + min(b_list)

for i in range(M):
    a_index,b_index,discount = map(int,input().split())
    
    price = a_list[a_index-1] + b_list[b_index-1] - discount
    
    cur_best = min(cur_best,price)
    
print(cur_best)

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

p = []
for i in range(M):
    s = input().split()
    p.append(int(a[int(s[0])-1])+int(b[int(s[1])-1])-int(s[2]))
p.append(low)
print(min(p))

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

for _ in range(M):
  x, y, c = map(int,input().split())
  price2 = a[x-1] + b[y-1] - c
  if price1 > price2:
    price1 = price2
print(price1)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline

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

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * (m + 1)
    count = 0

    for i in range(m):
        res[count] = alist[int(waribiki[i][0])-1] + blist[int(waribiki[i][1])-1] - int(waribiki[i][2])
        count += 1

    res[count] = min(alist) + min(blist)
      
    print(min(res))


if __name__ == '__main__':
    main()

Solution (Python):
frege_count, oven_count, coupon_count = map(int,input().split())	
frege_prices = list(map(int,input().split()))	
oven_prices = list(map(int,input().split()))	
coupon_list = [list(map(int, input().split())) for i in range(coupon_count)]

minprice = min(frege_prices) + min(oven_prices)
for coupon in coupon_list:
  total_cost = frege_prices[coupon[0]-1] + oven_prices[coupon[1]-1] - coupon[2]
  if minprice > total_cost:
          minprice = total_cost
print(minprice)

Solution (Python):



a,b,m = [int(x) for x in input().split()]
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = []
for i in range(m):
    ml.append([int(x) for x in input().split()])

ans = min(al) + min(bl)

for i in range(m):
    tmp = al[ml[i][0]-1] + bl[ml[i][1]-1] - ml[i][2]
    if tmp < ans:
        ans = tmp

print(ans)

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

Solution (Python):
A, B, M = map(int,input().split())
val_m = [[0] * 3 for i in range(M)]

val_a = list(map(int, input().split()))
val_b = list(map(int, input().split()))

for i in range(M):
  val_m[i][0], val_m[i][1], val_m[i][2] = map(int, input().split())

dis_val = []
for i in range(M):
  dis_val.append(val_a[val_m[i][0]-1] + val_b[val_m[i][1]-1] - val_m[i][2])

val_a = list(set(val_a))
val_b = list(set(val_b))

val_a.sort()
val_b.sort()
dis_val.sort()

sum_val = val_a[0] + val_b[0]
if(sum_val <= dis_val[0]):
  print(sum_val)
else:
  print(dis_val[0])

Solution (Python):
a, b, m = input().split()
a, b, m = int(a), int(b), int(m)
a_values = input().split()
b_values = input().split()
m_values = {}
for i in range(m):
    m_values[i] = input().split()

min_num = int(a_values[int(m_values[0][0]) - 1]) + int(b_values[int(m_values[0][1]) - 1]) - int(m_values[0][2])
for i in range(1, m):
    now = int(a_values[int(m_values[i][0]) - 1]) + int(b_values[int(m_values[i][1]) - 1]) - int(m_values[i][2])
    if min_num > now:
        min_num = now
now = int(min(a_values)) + int(min(b_values))
if min_num > now:
    print(now)
else:
    print(min_num)

Solution (Python):
import sys

def load(vtype=int):
    return vtype(input().strip())


def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]

A, B, M = tuple(load_list())

a = load_list()
b = load_list()

coupon = dict()
for _ in range(0, M):
    x, y, c = tuple(load_list())
    if (x-1, y-1) in coupon:
        coupon[(x-1,y-1)] = max(coupon[(x-1,y-1)], c)
    else:        
        coupon[(x-1,y-1)] = c 

minv = min(a) + min(b)

for key in coupon.keys():
    i, j = key
    minv = min(minv, a[i] + b[j] - coupon[(i, j)])

print(minv)

Solution (Python):
a, b, m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
ml = []

ml = [input().split() for i in range(m)]

mp = min(al) + min(bl)
mpl = []

for i in range(m):
    aa = int(ml[i][0])
    bb = int(ml[i][1])

    mpl.append(int(al[aa - 1]) + int(bl[bb - 1]) - int(ml[i][2]))

print(min(mp, min(mpl)))

Solution (Python):
A,B,M = list(map(int, input().split()))
AP = list(map(int, input().split()))
BP = list(map(int, input().split()))
MC = list(input().split() for i in range(M))


TPX = min(AP)+min(BP)


TPY = 0
for i in range(M):
    TPZ = AP[int(MC[i][0])-1] + BP[int(MC[i][1])-1] - int(MC[i][2])
    if i == 0:
        TPY = TPZ
    else:
        if TPZ < TPY:
            TPY = TPZ
print(min(TPX,TPY))

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
ad={}
for i in range(len(a)):ad[i]=a[i]
b=list(map(int,input().split()))
bd={}
for i in range(len(b)):bd[i]=b[i]
m=min(a)+min(b)
for _ in range(M):
    x,y,c=map(int,input().split())
    s=ad[x-1]+bd[y-1]-c
    m=min(m,s)
print(m)

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

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

m = [0] * M
x = [0] * M
y = [0] * M
for i in range (M):
    x[i], y[i], m[i] = map(int, input().split())
    

discount = [0] * M
for i in range(M):
    discount[i] = a[x[i]-1] + b[y[i]-1] - m[i]
    
    
discount_ab = min(a) + min (b)
if discount_ab > min(discount):
    print(min(discount))
else:
    print(discount_ab)

Solution (Python):


import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

A, B, M = MI()
a = LI()
b = LI()
xyc = LRI(M)

ans = min(a) + min(b)

for i in range(M):
    wari = xyc[i]
    aa = a[wari[0]-1] + b[wari[1]-1] - wari[2]
    ans = min(ans, aa)

print(ans)

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

minimum_price_with_discount = 0

for i in range(M):
    x, y, c = (int(x) for x in input().split())
    price_with_discount = a_s[x-1] + b_s[y-1] - c
    if i == 0:
        minimum_price_with_discount = price_with_discount
    else:
        if minimum_price_with_discount > price_with_discount:
            minimum_price_with_discount = price_with_discount
        else:
            continue

a_s.sort(), b_s.sort()
minimum_price_without_discount = a_s[0] + b_s[0]

if minimum_price_with_discount > minimum_price_without_discount:
    print(minimum_price_without_discount)
else:
    print(minimum_price_with_discount)

Solution (Python):
a, b, m = map(int, input().split())
priceOfMicrowaves = list(map(int, input().split()))
priceOfRefrigerators = list(map(int, input().split()))
priceTable = [list(map(int,input().split())) for i in range(m)]
cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]-price[2] >= cheepest:
        continue
    elif priceOfRefrigerators[price[1]-1]-price[2] >= cheepest:
        continue
    elif priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
if cheepest > min(priceOfMicrowaves) + min(priceOfRefrigerators):
    cheepest = min(priceOfMicrowaves) + min(priceOfRefrigerators)
print(cheepest)

Solution (Python):
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

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

a.sort()
b.sort()

for i in a:
    if i + b[0] > minimum:
        break
    for j in b:
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
            break

print(minimum)

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

minimum_price_with_discount = 0

for i in range(M):
    x, y, c = (int(x) for x in input().split())
    price_with_discount = a_s[x-1] + b_s[y-1] - c
    if i == 0:
        minimum_price_with_discount = price_with_discount
    else:
        if minimum_price_with_discount > price_with_discount:
            minimum_price_with_discount = price_with_discount
        else:
            continue

a_s.sort(), b_s.sort()
minimum_price_without_discount = a_s[0] + b_s[0]

if minimum_price_with_discount > minimum_price_without_discount:
    print(minimum_price_without_discount)
else:
    print(minimum_price_with_discount)

Solution (Python):
inp = input().split(" ")
A=int(inp[0])
B=int(inp[1])
M=int(inp[2])

if A!=0:
    a=input().split(" ")
else:
    a=[0]
if B!=0:
    b=input().split(" ")
else:
    b=[0]

s=[0]*(M+(1))
m=[[0]*3]*M
i=0
for x in m:
    x=input().split(" ")
    s[i]=int(a[int(x[0])-1])+int(b[int(x[1])-1])-int(x[2])
    i+=1

s[i]=int(min(a))+int(min(b))

print(min(s))

Solution (Python):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
K = min(a)+min(b)
X = 10**9
for i in range(M):
    x,y,c = map(int,input().split())
    S = a[x-1]+b[y-1]-c
    if S<X:
        X = S
if X<K:
    print(X)
else:
    print(K)

Solution (Python):
import numpy as np
A,B,M = map(int,input().rstrip().split())
a = list(map(int,input().rstrip().split()))
b = list(map(int,input().rstrip().split()))

minp = min(a) + min(b)

minpp = 10**6
for k in range(M):
  i,j,c = map(int,input().rstrip().split())
  minpp = min(a[i-1]+b[j-1]-c,minpp)

print(min(minp,minpp))

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


aSortedLst = sorted(aLst)
bSortedLst = sorted(bLst)
price = aSortedLst[0] + bSortedLst[0]


for i in range(m):
    x, y, c = map(int, input().split())
    disPrice = aLst[x - 1] + bLst[y - 1] - c
    if disPrice < price:
        price = disPrice
print(price)

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

mini = min(a) + min(b)

total = []
for i in s:
    total.append(a[int(i[0])-1]+b[int(i[1])-1]- int(i[-1]))
    
mini_2 = min(total)

if mini <= mini_2:
    print(mini)
else:
    print(mini_2)

Solution (Python):
a,b,m = list(map(int,input().split()))
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))
l = []
for rep in range(m):
	x,y,c = list(map(int,input().split()))
	p = arr[x-1] + brr[y-1] - c
	l.append(p)
alt = min(arr) + min(brr)
print(min(min(l),alt))

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 = 10**10
ma = max(c)

am = min(a)
bm = min(b)
mae = am + bm 


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

Solution (Python):
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
price2=int(min(vecA)) + int(min(vecB))
if price2<=price:
    price=price2
print(price)

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

f=list(map(int,input().split()))
r=list(map(int,input().split()))
    
ans=min(f)+min(r)

for i in range(m):
    x,y,p=map(int,input().split())
    ans=min(ans,f[x-1]+r[y-1]-p)

print(ans)

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

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

x = list()
y = list()
c = list()
for i in range(M):
    xi, yi, ci = map(int,input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)

p = list()

amin = min(a)
bmin = min(b)
pab  = amin + bmin
p.append(pab)
        
for i in range(M):
    pi = a[x[i]-1] + b[y[i]-1] - c[i]
    p.append(pi)

print(min(p))

Solution (Python):
A,B,M=map(int,input().split())
aList=list(map(int,input().split()))
bList=list(map(int,input().split()))
mab=min(aList)+min(bList)
for i in range(M):
  x,y,c=map(int,input().split())
  tt=aList[x-1]+bList[y-1]-c
  if mab > tt:
    mab=tt
print(mab)

Solution (Python):

list_num = input().split(" ") 
list_ref = input().split(" ") 
list_ren = input().split(" ") 
list2 = [] 
for i in range(int(list_num[2])):
    list_c = input().split(" ")
    list2.append(list_c)
A = int(list_num[0])
B = int(list_num[1])
M = int(list_num[2])

list_price = []


list_ref_int = [int(s) for s in list_ref]
list_ren_int = [int(s) for s in list_ren]
cheap = min(list_ref_int) + min(list_ren_int)
list_price.append(cheap)


for k in range(M):
    price = list_ref_int[int(list2[k][0])-1] + list_ren_int[int(list2[k][1])-1] - int(int(list2[k][2])-1) - 1
    list_price.append(price)

print(min(list_price))