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):
nA, nB, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A = [0] + A
B = [0] + B


X = [[] for _ in range(M)]
Y = [[] for _ in range(M)]
C = [[] for _ in range(M)]

for i in range(M):
    X[i], Y[i], C[i] = map(int, input().split())


ans1 = min(A[1:]) + min(B[1:])


ans2 = max(A) + max(B)
for x, y, c in zip(X, Y, C):
    ans2 = min(ans2, A[x] + B[y] - c)

print(min(ans1, ans2))

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)













def main():
    
    A,B,M=mi()
    a=li()
    b=li()
    answer=min(a)+min(b)
    for i in range(M):
        x,y,c=mi()
        answer=min(answer,a[x-1]+b[y-1]-c) 
    print(answer)   

















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')



""" main function"""

if __name__ == '__main__':
    main()

Solution (Python):
A, B, M = map(int, input().split())
lis_a = list(map(int, input().split()))
lis_b = list(map(int, input().split()))
lis_price = []

lis_price.append(min(lis_a) + min(lis_b))

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

print(min(lis_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)]

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

for i in range(m):
    a_i = xyc[i][0] - 1
    b_i = xyc[i][1] - 1
    c_i = xyc[i][2]
    pri = a[a_i] + b[b_i] - c_i
    ans = min(ans,pri)

print(ans)

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

ans = min(A) + min(B)

for c in C:
    if (A[c[0]-1]+B[c[1]-1]-c[2])<ans:
        ans = A[c[0]-1]+B[c[1]-1]-c[2]
print(ans)

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

ans = min(pa) + min(pb)
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    ans = min(ans, pa[x] + pb[y] - c)

print(ans)

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

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

print( min(min(a) + min(b),  min( [a[i[0]-1] + b[i[1]-1] - i[2] for i in mlist ])))

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

lis=[min(A)+min(B)]

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

print(min(lis))

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 = 0
lpr = min(a) + min(b)
dcp = []

for i in range(M):
    indexA = xyc[i][0] - 1
    indexB = xyc[i][1] - 1
    dcp.append(a[indexA] + b[indexB] - xyc[i][2])

ans = min(min(dcp), lpr)
print(ans)

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

min_a = min(a)
min_b = min(b)
money = min_a + min_b

for i in range(m):
    kingaku = a[x[i][0]-1] + b[x[i][1]-1] - x[i][2]
    if kingaku < money:
        money = kingaku

print(money)

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

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

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

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

a, b, m = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
xyc = []
for _ in range(m):
    xyc.append([int(x) for x in input().split()])
ans = min(A) + min(B)
for i in range(m):
    x, y, c = xyc[i]
    temp = A[x - 1] + B[y - 1] - c
    ans = min(ans, temp)
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()]
x = []
for m in range(M):
    x.append([int(i) for i in input().split()])
_min = min(a)+min(b)
		
for i in x:
    _min = min( (a[i[0]-1]+b[i[1]-1] - i[2]),_min)
print(_min)

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

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

Solution (Python):
a_b_m_var = input().split()
a_i_var = input().split()
b_i_var = input().split()

a_b_m = [int(s) for s in a_b_m_var]
a_i = [int(s) for s in a_i_var]
b_i = [int(s) for s in b_i_var]

not_discount_price = min(a_i) + min(b_i)

down_price_i = []
for i in range(a_b_m[2]):
    price_down_var = input().split()
    price_down = [int(s) for s in price_down_var]
    a, b, m = price_down[0], price_down[1], price_down[2]
    price = a_i[a-1] + b_i[b-1] - m
    down_price_i.append(price)

if not_discount_price > min(down_price_i):
    print(min(down_price_i))
else:
    print(not_discount_price)

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

Solution (Python):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [list(map(int, input().split())) for i in range(a[2])]
e = [min(b) + min(c)]
for f in d:
  e.append(b[f[0] - 1] + c[f[1] - 1] - f[2])
print(min(e))

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

res = 10**6

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

a.sort()
b.sort()
print(min(res, a[0]+b[0]))

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)]
min_a=min(a)
min_b=min(b)

min_cost=min_a+min_b
for _m in m:
  cost=a[_m[0]-1]+b[_m[1]-1]-_m[2]
  min_cost=min(min_cost,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()))
minimum = min(a)+min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    minimum = min(a[x-1]+b[y-1]-c, minimum)
print(minimum)

Solution (Python):
def main():
    a, b, m = map(int, input().split())
    
    
    f_list = list(map(int, input().split()))
    
    m_list = list(map(int, input().split()))
    
    t_list = [list(map(int, input().split())) for _ in range(m)]
    
    p_list = []
    
    
    p_list.append(min(f_list) + min(m_list))
    for t in t_list:
        p_list.append(f_list[t[0]-1] + m_list[t[1]-1] - t[2])
    
    ans = min(p_list)
    print(ans)
    

if __name__ == '__main__':
    main()

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

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

    a.sort()
    b.sort()
    dis.sort()
    ans = min(a[0] + b[0], dis[0])
    print(ans)

    return


resolve()

Solution (Python):
a, b, m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(m)]
kouho = [min(a)+min(b)]

for l in li:
    kouho.append(a[l[0]-1] + b[l[1]-1] -l[2])

print(min(kouho))

Solution (Python):
if __name__ == '__main__':
   a, b, n = map(int, input().split())
   lista =  [int(i) for i in input().split()]
   listb =  [int(i) for i in input().split()]
   minP = min(lista) + min(listb)

   for i in range(n):
       c = [int(i) for i in input().split()]
       now =lista[c[0]-1] + listb[c[1]-1] - c[2]
       if  now< minP :
           minP=now

   print(minP)

Solution (Python):
A,B,M=map(int,input().split())
at=list(map(int,input().split()))
bt=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(M)]

minc=min(at)+min(bt)

for i in range(M):
    minc=min(minc,at[xyc[i][0]-1]+bt[xyc[i][1]-1]-xyc[i][2])
    
print(minc)

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()]
x = []
y = []
c = []
for _ in range(M):
    xt, yt, ct = [int(x) for x in input().split()]
    x.append(xt)
    y.append(yt)
    c.append(ct)


ret = min(a) + min(b)


for i in range(len(x)):
    t = a[x[i] - 1] + b[y[i] - 1] - c[i]
    if ret > t:
        ret = t

print(ret)

Solution (Python):
a,b,m=map(int,input().split())
ali= list(map(int,input().split()))	
bli= list(map(int,input().split()))	
min=min(ali)+min(bli)
for i in range(0,m):
  x,y,c=map(int,input().split())
  mon=ali[x-1]+bli[y-1]-c
  if mon<min:
    min=mon
    
print(min)

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

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

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

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

print(ans)

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

def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 10**6

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

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

    print(ans)

main()

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

def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 10**6

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

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

    print(ans)

main()

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

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

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

print(ans)

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

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())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
X = []
Y = []
C = []
for i in range(m):
    x, y, c = [int(j) for j in input().split()]
    X.append(x)
    Y.append(y)
    C.append(c)


pricelist = [min(A) + min(B)]
for i in range(m):
    pricelist.append(A[X[i]-1] + B[Y[i]-1] - C[i])
print(min(pricelist))

Solution (Python):






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





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

Solution (Python):
a,b,m=map(int,input().split())
at=list(map(int,input().split()))
bt=list(map(int,input().split()))
ans=min(at)+min(bt)
for i in range(m):
  x,y,c=map(int,input().split())
  ans=min(ans,at[x-1]+bt[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()))

payl = []
nom = min(al) + min(bl)
payl.append(nom)

for i in range(m):
    ml = list(map(int, input().split()))
    payl.append(al[ml[0] - 1] + bl[ml[1] - 1] - ml[2])

print(min(payl))

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

Solution (Python):
(a,b,m),x,y,*c=[list(map(int, i.split())) for i in open(0)]
print(min([x[~-i]+y[~-j]-k for i,j,k in c]+[min(x)+min(y)]))

Solution (Python):

import sys


def solve(
    A: int,
    B: int,
    M: int,
    a: "List[int]",
    b: "List[int]",
    x: "List[int]",
    y: "List[int]",
    c: "List[int]",
):
    
    min_refrigerator = min(a)
    min_microwave = min(b)
    not_use_coupon = min_refrigerator + min_microwave

    max_sale = max(c)
    use_coupon = 2000000
    for xi, yi, ci in zip(x, y, c):
        use_coupon = min(use_coupon, a[xi - 1] + b[yi - 1] - ci)

    ans = min(use_coupon, not_use_coupon)
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    M = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(A)]  
    b = [int(next(tokens)) for _ in range(B)]  
    x = [int()] * (M)  
    y = [int()] * (M)  
    c = [int()] * (M)  
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

input = sys.stdin.readline


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

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

    print(ans)


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

ans=float('inf')
for i in range(M):
  x,y,c=[int(x) for x in input().rstrip().split()]
  ans=min(ans,a[x-1]+b[y-1]-c)
mm=min(a)+min(b)
print(min(ans,mm))

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

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 _ 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 = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for i in range(m)]

ans = min(a_list) + min(b_list)

for i in range(m):
    ans = min(ans, a_list[m_list[i][0] - 1] + b_list[m_list[i][1] - 1] - m_list[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()))
cost=min(a)+min(b)
for i in range(M):
    x,y,c=map(int,input().split())
    cost=min(cost,a[x-1]+b[y-1]-c)
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())
    x -= 1
    y -= 1
    z = A[x]+B[y]-c
    if z < ans:
        ans = z
print(ans)

Solution (Python):
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = []
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    AB.append(A[x]+B[y]-c)
AB.sort()
A.sort()
B.sort()
print(min(AB[0], A[0]+B[0]))

Solution (Python):
A, B, M = map(int, input().split())
PA = [int(x) for x in input().split()]
PB = [int(x) for x in input().split()]
XYC = [tuple(map(int, input().split())) for _ in range(M)]

p1 = min(PA) + min(PB)
p2 = 10 ** 10
for x, y, c in XYC:
    p2 = min(PA[x - 1] + PB[y - 1] - c, p2)

print(min(p1, p2))

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()]
XYC = [[int(x) for x in 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):
A,B,M=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
XC=[]
for i in range(M):
  XC.append(list(map(int,input().split())))
ans=min(aa)+min(bb)
for i in range(M):
  ans=min(ans,aa[XC[i][0]-1]+bb[XC[i][1]-1]-XC[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()))

ans = min(a)+min(b)

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

print(ans)

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
a,b,m = readInts()
A = readInts()
B = readInts()
res = min(A) + min(B)
for i in range(m):
    x,y,c = readInts()
    x -=1;y-=1;
    res = min(res,A[x] + B[y] - c)
print(res)

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())))
ans = min(a) + min(b)

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

Solution (Python):
a, b, m = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = []
for _ in range(m):
  x, y, c = map(int, input().split())
  x, y = x-1, y-1
  li_c.append(li_a[x]+li_b[y]-c)
li_a.sort()
li_b.sort()
li_c.sort()
ans = min(li_a[0]+li_b[0], li_c[0])
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 _ in range(m)]
ans = min(a) + min(b)
for i in range(m):
    ans = min(ans, a[c[i][0]-1]+b[c[i][1]-1]-c[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()))
ans = 1000000000000000
for i in range(M):
    x,y,c = map(int,input().split())
    ans = min(ans,a[x-1]+b[y-1]-c)
ans = min(ans,min(a)+min(b))
print(ans)

Solution (Python):
a,b,m=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
minimum=100000000000000
for i in range(m):
  x,y,z=map(int,input().split())
  minimum=min(minimum,alist[x-1]+blist[y-1]-z)
alist.sort()
blist.sort()
minimum=min(minimum,alist[0]+blist[0])
print(minimum)

Solution (Python):
A, B, M = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
ans = min(an)+min(bn)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, an[x-1] + bn[y-1] - c)
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()))
xyc = [list(map(int,input().split())) for _ in range(m)]
a_min = min(a_list)
b_min = min(b_list)
s = a_min + b_min
for i in range(m):
    x,y,c = xyc[i][0]-1,xyc[i][1]-1,xyc[i][2]
    s = min(s, a_list[x]+b_list[y]-c)
print(s)

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 s in range(m)]
ans = []
for m in mlist:
	tmp = alist[m[0]-1] + blist[m[1]-1] -m[2]
	ans.append(tmp)
x = min(alist) + min(blist)
ans.append(x)
print(min(ans))

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

oldp = min(a)+min(b)

for _ in range(M):
    x, y, cp = map(int,input().split())
    p = a[x-1]+b[y-1]-cp
    if oldp > p:
        oldp = p

print(oldp)

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

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

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

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


result = min(a) + min(b)


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

print(result)

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)








a,b,m=n1()
A=n1()
B=n1()
X=n3(m)

A2=sorted(A)
B2=sorted(B)
ans=A2[0]+B2[0]
for a,b,c in X:
    if A[a-1]+B[b-1]-c<ans:
        ans=A[a-1]+B[b-1]-c
    
print(ans)

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)








a,b,m=n1()
A=n1()
B=n1()
X=n3(m)

A2=sorted(A)
B2=sorted(B)
ans=A2[0]+B2[0]
for a,b,c in X:
    if A[a-1]+B[b-1]-c<ans:
        ans=A[a-1]+B[b-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()))



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)