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 = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
d = [[0]*3 for i in range(M)]
for i in range (M):
    d[i][0],d[i][1],d[i][2] = map(int,input().split())

now_min = min(a)+min(b)
mim = 10**9
for i in range(M):
    if a[d[i][0]-1] + b[d[i][1]-1] - d[i][2] <= mim:
        mim = a[d[i][0]-1] + b[d[i][1]-1] - d[i][2]

print(min(now_min,mim))

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

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


ans = [min(alist)+min(blist)]

for i in range(m):
    x = s[i][0]
    y = s[i][1]
    c = s[i][2]
    p = alist[x-1] + blist[y-1] - c
    ans.append(p)

print(min(ans))

Solution (Python):
a,b,m= list(map(int, input().split()))
ia = list(map(int, input().split()))
ib= list(map(int, input().split()))
z=min(ia)+min(ib)
for j in range(m):
    k= list(map(int, input().split()))
    bn=ia[(k[0]-1)]+ib[(k[1]-1)]-k[2]
    if z>bn:
        z=bn
print(z)

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

minprice = min(a)+min(b)
for i in range(M):
    p = a[c[i][0]-1]+b[c[i][1]-1]-c[i][2]
    minprice = min(p, minprice)

print (minprice)

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def fft(A, B):
    """ 
    高速フーリエ変換(FFT)
        A：出現回数をカウントしたリスト
        B：出現回数をカウントしたリスト
    """
    import numpy as np
    from numpy.fft import rfft, irfft

    
    MAXA = max(A)
    MAXB = max(B)
    C1 = [0] * (MAXA+1)
    C2 = [0] * (MAXB+1)
    for a in A:
        C1[a] += 1
    for b in B:
        C2[b] += 1
    
    L = 1
    k = 0
    while L <= MAXA + MAXB:
        k += 1
        L = 2**k
    
    res = irfft(rfft(C1, L) * rfft(C2, L), L)
    
    res = np.rint(res).astype(np.int64)
    return res

N, M, L = MAP()
A = LIST()
B = LIST()

res = list(fft(A, B))

mn = INF
for i, a in enumerate(res):
    if a != 0:
        mn = i
        break

for _ in range(L):
    x, y, c = MAP()
    x -= 1; y -= 1
    mn = min(mn, A[x] + B[y] - c)
print(mn)

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    a, b, m = rli()
    la = rli()
    lb = rli()
    ans = min(la)+min(lb)
    for i in range(m):
        x, y, c = rli()
        x -= 1
        y -= 1
        ans = min(ans, la[x]+lb[y]-c)
    print(ans)


if __name__ == '__main__':
    main()

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


xymin=min(ai)+min(bi)

for i in range(m):

    x,y,c=map(int, input().split())
    xy=ai[x-1]+bi[y-1]-c
    if xymin>xy:
        xymin=xy

print(xymin)

Solution (Python):
a, b, m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
XYZ = []
for i in range(m):
    XYZ.append(list(map(int,input().split())))
ans = 10**5+10**5
for i in range(m):
    a_num = XYZ[i][0]
    b_num = XYZ[i][1]
    if A[a_num-1]+B[b_num-1]-XYZ[i][2] < ans:
        ans = A[a_num-1]+B[b_num-1]-XYZ[i][2]
minAB = min(A) + min(B)
if ans < minAB:
    print(ans)
else:
    print(minAB)

Solution (Python):
a, b, m  = [int(x) for x in input().split()]
a_l = [int(x) for x in input().split()]
b_l = [int(x) for x in input().split()]
ans = min(a_l) + min(b_l)
for mm in range(m):
    xm, ym, cm = [int(x) for x in input().split()]
    anss = a_l[xm - 1] + b_l[ym - 1] - cm
    if anss < ans:
        ans = anss
print(ans)

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

Solution (Python):
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
na, nb, nm = i2()
a = intl()
b = intl()
mp = min(a)+min(b)
for i in range(nm):
    x , y , c = i2()
    p = a[x-1]+b[y-1]-c
    if (p) < mp:
        mp = p
print(mp)

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

mn=min(al)+min(bl)

for i in range(m):
    price=0
    x,y,c=map(int,input().split())
    price=al[x-1]+bl[y-1]-c
    if mn>price:
        mn=price
print(mn)

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 = 2*10**5

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

    aryA = [int(v) for v in input().split()]
    aryB = [int(v) for v in input().split()]

    minPrice = min(aryA) + min(aryB)

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

        x -= 1
        y -= 1

        minPrice = min(minPrice, aryA[x] + aryB[y] - c)

    print(minPrice)


main()

Solution (Python):
A, B, M = map(int, input().split())
prices_A = list(map(int, input().split()))
prices_B = list(map(int, input().split()))
coupons = [tuple(map(int, input().split())) for _ in range(M)]
possible_purchases = []
for coupon in coupons:
    combination_price = prices_A[coupon[0]-1] + prices_B[coupon[1]-1] - coupon[2]
    possible_purchases.append(combination_price)
possible_purchases.append(min(prices_A)+min(prices_B))
print(min(possible_purchases))

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):
    ai, bi, c = map(int, input().split())
    cost = min(cost, a[ai-1] + b[bi-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()))

min_price = min(A) + min(B)

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

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

print(ans)

Solution (Python):
if __name__ == "__main__":
    a, b, m = map(int, input().split())

    refrigerator = list(map(int, input().split()))
    microwave = list(map(int, input().split()))
    tickets = list()
    for i in range(m):
        tickets.append(list(map(int, input().split())))

    ans = min(refrigerator) + min(microwave)

    for i in range(m):
        t = tickets[i]
        tmp = refrigerator[t[0]-1] + microwave[t[1]-1] - t[2]
        if tmp < ans:
            ans = tmp

    print(ans)

Solution (Python):

import sys

def solve(nA: int, nB: int, M: int, A: "List[int]", B: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):

    cheapest = -1 


    for m in range(M):
        price = A[x[m]-1] + B[y[m]-1] - c[m] 
        if cheapest == -1 or cheapest >= price:
            cheapest = price

    if cheapest >= min(A)+min(B):
        cheapest = min(A)+min(B)

    print(cheapest)
    
    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):
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,m = mi()
av = li()
bv = li()

avs = av.copy()
bvs = bv.copy()
avs.sort()
bvs.sort()

ans = avs[0] + bvs[0]

for i in range(m):
    q = li()
    tmp = av[q[0]-1] + bv[q[1]-1] - q[2]
    ans = min(ans, tmp)

print(ans)

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

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

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

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

ans = min(alist) + min(blist)

for i in range(m):
    x, y, c = map(int, input().split())
    x -= 1  
    y -= 1  
    if alist[x] + blist[y] - c < ans:
        ans = alist[x] + blist[y] - c
    else:
        continue

print(ans)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat)


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def main():
    A, B, M = MI()
    a = LI()
    b = LI()
    x = [0] * M
    y = [0] * M
    c = [0] * M
    ans = 10**9
    
    
    
    

    for i in range(M):
        x[i], y[i], c[i] = MI()

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

        
        
        

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

    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())
  discount = a[(x-1)] + b[(y-1)] - c
  if (discount < ans):
    ans = discount
print(ans)

Solution (Python):
from sys import stdin
a,b,m  = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
M = []
for i in range(m):
    M.append([int(x) for x in stdin.readline().rstrip().split()])
t = []
for i in range(m):
    t.append(A[M[i][0]-1] + B[M[i][1]-1] - M[i][2])
t = min(t)
k = min(A) + min(B)
print(min(t,k))

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

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]"):
    
    MINB = min(b)
    
    waribiki = [[] for _ in range(A)]
    for i in range(M):
        waribiki[x[i]-1].append((y[i]-1,c[i]))
    
    answer = 10**18

    for i in range(A):
        aa = a[i]
        for b_idx,cc in waribiki[i]:
            answer = min(aa+b[b_idx]-cc,answer)
        
        answer = min(aa+MINB,answer)
    print(answer)
    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):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = min(a) + min(b)

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

print(c)

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

ans = 10**9
for i in range(M):
    x,y,c = [int(i) for i in input().split()]
    if ans > a[x-1] + b[y-1] - c:
        ans = a[x-1] + b[y-1] - c
if ans > min(a) + min(b):
    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()))
XYC = [list(map(int,input().split())) for i in range(m)]

kouho = (min(A)+min(B))
for i in range(m):
    kouho = min(kouho,A[XYC[i][0]-1] + B[XYC[i][1]-1] - XYC[i][2])

print(kouho)

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

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())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
cheap = min(ai)+min(bi)
for i in range(m):
    x,y,c = map(int,input().split())
    cheap = min(ai[x-1]+bi[y-1]-c,cheap)
print(cheap)

Solution (Python):
def main():
    a, b, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    ans = min(A) + min(B)
    for mi in range(m):
        x, y, c = [int(e) for e in input().split()]
        ans = min(A[x - 1] + B[y - 1] - c, ans)

    print(ans)

if __name__ == "__main__":
    main()

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

AList = list(map(int, input().split(' ', A)))
BList = list(map(int, input().split(' ', B)))

result = 10 ** 10
DisList = []
for i in range(M):
    tmpList = list(map(int, input().split()))
    if result > AList[tmpList[0] - 1] + BList[tmpList[1] - 1] - tmpList[2]:
        result = AList[tmpList[0] - 1] + BList[tmpList[1] - 1] - tmpList[2]

AList.sort()
BList.sort()

if result > AList[0] + BList[0]:
    result = AList[0] + BList[0]

print(result)

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 _ in range(M)]


ans = min(As) + min(Bs)
for m in Ms:
  a = int(m[0])-1
  b = int(m[1])-1
  rate = int(m[2])
  price = int(As[a])+int(Bs[b])-rate
  if price < ans:
    ans = price
print(ans)

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

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

print(min)

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

main()

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

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



mymin = (min(alist)+min(blist))
for m in range(M):
    x, y, c = map(int, input().split())
    if alist[x-1] + blist[y-1] - c < mymin:
        mymin = alist[x-1] + blist[y-1] - c
print(mymin)

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

a_prices = [int(i) for i in input().split()]
b_prices = [int(i) for i in input().split()]

min_price = min(a_prices) + min(b_prices)

for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    min_price = min(min_price, a_prices[x] + b_prices[y] - c)
print(min_price)

Solution (Python):
lena, lenb, lenm = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
m = []
m.append(min(a) + min(b))
for i in range(lenm):
    x, y, c = [int(i) for i in input().split()]
    m.append(a[x - 1] + b[y - 1] - c)

print(min(m))

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

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

for x in l:
  arr.append(a[x[0]-1]+b[x[1]-1]-x[2])
print(min(arr))

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, M = LI()
a = LI()
b = LI()
xyc = [[] for i in range(M)]
for i in range(M):
    x, y, c = LI()
    x -= 1
    y -= 1
    xyc[i] = [x, y, c]

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

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

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

def main():
    A,B,M=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ans=2*10**5
    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)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
A, B, M = map(int, input().rstrip().split(' '))
a = list(map(int, input().rstrip().split(' ')))
b = list(map(int, input().rstrip().split(' ')))
coupon = []

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

min_price = min(coupon)

if min(a)+min(b) < min_price :
  print(min(a)+min(b))
else:
  print(min_price)

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

ans = min(a) + min(b)

for x, y, c in xyc:
    d = a[x-1] + b[y-1] - c
    if ans > d:
        ans = d

print(ans)

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

ans = min(a)+min(b)
for i in range(M):
  tmp = a[x[i]-1]+b[y[i]-1]-c[i]
  if tmp < ans:
    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()))

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

saisho1 = min(a) + min(b)

kouho = [0 for i in range(M)]

for i in range(M):
  kouho[i] = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]

saisho2 = min(kouho)

print(min(saisho1, saisho2))

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

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 k in range(M)]
ans = min(a) + min(b)
for k in range(M):
    cos = a[m[k][0]-1] + b[m[k][1]-1] - m[k][2]
    if ans > cos:
        ans = cos

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

ans = min(a)+min(b)

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

print(ans)

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

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

print(ans)

Solution (Python):
a,b,m = map(int,input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
amin = min(As)
bmin = min(Bs)

xycs = []
comb = []
for i in range(m):
    x, y, c = map(int, input().split())
    comb.append(As[x-1] + Bs[y-1] - c)

print(min(amin+bmin, min(comb)))

Solution (Python):
A, B, m = list(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)]

anses = [min(a) + min(b)]

for x, y, c in xyc:
  x -= 1
  y -= 1
  anses.append(a[x] + b[y] - c)

print(min(anses))

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

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

m = min(a) + min(b)

M = float('inf')
for x,y,c in xyc:
    x -= 1
    y -= 1
    tmp = a[x] + b[y] - c
    M = min(M,tmp)

if m>M:
    print(M)
else:
    print(m)

Solution (Python):

a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a_idx = a.index(min(a))
b_idx = b.index(min(b))


ans = min(a)+min(b)
for i in range(m):
    x,y,c = map(int,input().split())
    if x-1 != a_idx or y-1 != b_idx:
        ans = min(ans,a[x-1]+b[y-1]-c)
    if x-1 == a_idx and y-1 == b_idx:
        ans = min(ans,a[x-1]+b[y-1]-c)
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 r 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):
import sys

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
IN = sys.stdin.readlines()

ans = min(a) + min(b)

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

print(ans)

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

if A > 1:
    F = [int(i) for i in input().split()]
else:
    F = [int(input())]
if B > 1:
    D = [int(i) for i in input().split()]
else:
    D = [int(input())]


i = F.index(min(F))
j = D.index(min(D))
price = F[i] + D[j]

for i in range(M):
    xi, yi, ci = map(int, input().split())
    price_iter = F[int(xi)-1] + D[int(yi)-1] - ci
    if price > price_iter:
        i = xi
        j = yi
        price = price_iter

print(price)

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

aas = input().split()
aas = [int(a) for a in aas]
as2 = sorted(aas)

bbs = input().split()
bbs = [int(b) for b in bbs]
bs2 = sorted(bbs)
mini = bs2[0] + as2[0]
xycs = []
for i in range(M):
  xyc = input().split()
  xycs.append([int(xyc[0]), int(xyc[1]), int(xyc[2])])
  
for xyc in xycs:
  a = aas[xyc[0]-1]
  b = bbs[xyc[1]-1]
  c = xyc[2]
  if a + b - c < mini:
    mini = a+b-c
print(mini)

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()]
mina = min(a)
minb = min(b)

ans = mina + minb

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

print(ans)

Solution (Python):
a,b,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
z = []
for _ in range(m):
    z.append(list(map(int,input().split())))
ans = min(x)+min(y)
for d in z:
    tmp = x[d[0]-1]+y[d[1]-1]-d[2]
    ans = min(tmp,ans)
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
minval = int(1e10)
for i in range(m):
    x[i], y[i], c[i] = map(int, input().split())
    val = a[x[i]-1] + b[y[i]-1] - c[i]
    if minval > val:
        minval = val
print(min(min(a) + min(b), minval))

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '
        
        
    return ret



from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from fractions import gcd


def lcm(a, b):
    
    g = gcd(a, b)
    return a * b // g


A, B, M = read_ints()
a = read_ints()
b = read_ints()

ans = 10 ** 9
for _ in range(M):
    x, y, c = read_ints()
    nedan = a[x - 1] + b[y - 1] - c
    ans = min(ans, nedan)

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