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


min_price = min(a) + min(b)

for i in range(m):
    arr = list(map(int, input().split()))
    discounted_price = a[arr[0] - 1] + b[arr[1] - 1] - arr[2]
    min_price = min(min_price, discounted_price)
print(min_price)

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

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]"):
    ans = min(a) + min(b)
    for i in range(M):
        xi = x[i]
        yi = y[i]
        ci = c[i]
        t = a[xi-1] + b[yi-1] - ci
        if ans >= t:
            ans = t
    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):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
price_list = []

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


a.sort()
b.sort()
price_list.append(a[0]+b[0])
min_price = price_list[0]

for n in price_list:
  if min_price >= n:
    min_price = n
  elif min_price < n:
    pass


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 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_list = [int(x.strip()) for x in input().split()]
b_list = [int(x.strip()) for x in input().split()]
ans = min(a_list)+min(b_list)
for i in range(m):
  ai,bi,ci = map(int,input().split())
  ch = a_list[ai-1]+b_list[bi-1]-ci
  if ch < ans:
    ans = ch
print(ans)

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

mini = min(a) + min(b)
for i in range(M):
    x,y,c = map(int,input().split())

    rei = a[x-1]
    den = b[y-1]
    coop = c

    if rei + den - coop < mini:
        mini = rei + den - coop

print(mini)

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,Z = map(int,input().split())
    x.append(X)
    y.append(Y)
    c.append(Z)

mini = min(a) + min(b)
for i in range(M):

    rei = a[x[i]-1]
    den = b[y[i]-1]
    coop = c[i]

    if rei + den - coop < mini:
        mini = rei + den - coop

print(mini)

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

cst = min(ai) + min(bi)

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

print(cst)

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


def main():
    _, _, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ans = 200001

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

    amin = min(a)
    bmin = min(b)

    if ans > amin + bmin:
        ans = amin + bmin

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
from numpy import array
input = lambda: stdin.readline().rstrip()
na, nb, m = map(int, input().split())
a = array(list(map(int, input().split())))
b = array(list(map(int, input().split())))
ans = min(a) + min(b)
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):
from sys import stdin
input = lambda: stdin.readline().rstrip()
na, nb, 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 -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
print(ans)

Solution (Python):
na, nb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min_b = 10**9
for i in range(na):
    min_a = min(min_a, a[i])
for i in range(nb):
    min_b = min(min_b, b[i])
ans = min_a + min_b
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):
from sys import stdin
input = lambda: stdin.readline().rstrip()
na, nb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min_b = 10**9
for i in range(na):
    min_a = min(min_a, a[i])
for i in range(nb):
    min_b = min(min_b, b[i])
ans = min_a + min_b
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):
na, nb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min_b = 10**9
for i in range(na):
    min_a = min(min_a, a[i])
for i in range(nb):
    min_b = min(min_b, b[i])
ans = min_a + min_b
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):
from sys import stdin
input = lambda: stdin.readline().rstrip()
na, nb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min_b = 10**9
for i in range(na):
    min_a = min(min_a, a[i])
for i in range(nb):
    min_b = min(min_b, b[i])
ans = min_a + min_b
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())
l_a=list(map(int,input().split()))
l_b=list(map(int,input().split()))
ans=[min(l_a)+min(l_b)]
for i in range(M):
  xi,yi,ci=map(int,input().split())
  ans.append(l_a[xi-1]+l_b[yi-1]-ci)
print(min(ans))

Solution (Python):
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

A,B,M = mi()
a = li()
b = li()
xyc = [li() for i in range(M)]

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

Solution (Python):

import sys
input=sys.stdin.readline
import heapq

def main():
    A=[]
    B=[]
    M=[]
    values=[]
    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)]


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

    heapq.heapify(A)
    heapq.heapify(B)


    cheap=heapq.heappop(A)+heapq.heappop(B)

    print(min(cheap,min(values)))

if __name__=="__main__":
    main()

Solution (Python):
import sys
import copy
l = [int(c) for c in input().split()]
A=l[0]
B=l[1]
M=l[2]
a=[int(c) for c in input().split()]
b=[int(c) for c in input().split()]
H = [list(map(int,input().split())) for c in range(M)]

a_sorted = sorted(a)
b_sorted = sorted(b)

MinPrice = a_sorted[0]+b_sorted[0]

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

print(MinPrice)

Solution (Python):
a, b, m = map(int, input().split())
a_l = list(map(int, input().split()))
b_l =  list(map(int, input().split()))
x_y_c = [ list(map(int, input().split())) for _ in range(m) ]

ans = min(a_l) + min(b_l)
for x,y,c in x_y_c:
   ans = min(a_l[x-1]+b_l[y-1]-c, ans)
print(ans)

Solution (Python):

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


X_Y_C = [list(map(int, input().split())) for _ in range(M)]


ans = min(ref_p) + min(mic_p)
for x, y, c in X_Y_C:
    temp = ref_p[x-1] + mic_p[y-1] - c

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

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

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def NLI(n):return [[int(i) for i in input().split()] for i in range(n)]
def NLI_(n):return [[int(i)-1 for i in input().split()] for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)]
def RI(a=1,b=10):return random.randint(a,b)
def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors')
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7

inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()













import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()


show_flg=False
show_flg=True

ans=0


_,_,m=LI()
a=LI()
b=LI()
ans=min(a)+min(b)
for i in range(m):
    x,y,c=LI_()
    ans=min(ans,a[x]+b[y]-c-1)
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 _ 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 = list(map(int, input().split()))
fridges = list(map(int, input().split()))
microwaves = list(map(int, input().split()))

price_min = min(fridges) + min(microwaves)
for _ in range(m):
	x, y, c = list(map(int, input().split()))
	price = fridges[x-1] + microwaves[y-1] - c
	if price < price_min:
		price_min = price
		
print(price_min)

Solution (Python):

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

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[input().split() for l in range(M)]
tot_1=min(a)+min(b)
lis=[]
for i in range(M):
    tot=a[int(x[i][0])-1]+b[int(x[i][1])-1]-int(x[i][2])
    lis.append(tot)
if tot_1<=min(lis):
    print(tot_1)
else:
    print(min(lis))

Solution (Python):

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

prices = []

prices.append(min(a) + min(b))

for k in range(M):
    prices.append(a[x[k] - 1] + b[y[k] - 1] - c[k])

print(min(prices))

Solution (Python):
def main():

    

    a_num, b_num, m = map(int, input().split())

    a_val = list(map(int, input().split()))
    b_val = list(map(int, input().split()))

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

    set_value = []
    for i in range(len(values)):
        set_value.append(a_val[values[i][0]-1] +
                         b_val[values[i][1]-1] - values[i][2])
    min_set_value = min(set_value)

    solo_value = min(a_val) + min(b_val)

    answer = min_set_value if min_set_value <= solo_value else solo_value

    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
def inpl(): return list(map(int, input().split()))
A, B, M = inpl()
A = inpl()
B = inpl()
res = min(A) + min(B)
for _ in range(M):
    x, y, c = inpl()
    tmp = A[x-1] + B[y-1] - c
    if tmp < res:
        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 _ 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())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ret = 2**60
for _ in range(m):
  x,y,c = map(int,input().split())
  x -= 1
  y -= 1
  ret = min(ret, A[x]+B[y]-c)
print( min(ret, min(A)+min(B)) )

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

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

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

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

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

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

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

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

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

m = 10000000

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

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

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

for i in range(m):
    x,y,c = map(int, input().split())
    z = ai[x-1] + bi[y-1] - c
    if z < tmp_min:
        tmp_min =  z

print(tmp_min)

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

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

mini = float('inf')

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

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

Solution (Python):
A,B,M = map(int,input().split())
AA = map(int,input().split())
AAA = list(AA)
BB = map(int,input().split())
BBB = list(BB)
mini = min(AAA) + min(BBB)
for i in range(M):
  x,y,c = map(int,input().split())
  xxx = AAA[x-1] + BBB[y-1] - c
  if mini >xxx:
    mini = xxx
print(mini)

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

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

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

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

price = min(a) + min(b)

for e in z:
    tmp_price = a[e[0]-1] + b[e[1]-1] - e[2]

    if(price > tmp_price):
        price = tmp_price

print(price)

Solution (Python):
def main():
    a, b, m = map(int, input().split())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    xyc_lst = [list(map(int, input().split())) for _ in range(m)]

    min_a = min(a_lst)
    min_b = min(b_lst)
    ans = min_a + min_b

    for i in range(m):
        x = xyc_lst[i][0]
        y = xyc_lst[i][1]
        c = xyc_lst[i][2]

        cost = a_lst[x - 1] + b_lst[y - 1] - c

        if cost < ans:
            ans = cost

    print(ans)


if __name__ == "__main__":
    main()

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

a_copy = a_price.copy()
a_copy.sort()
b_copy = b_price.copy()
b_copy.sort()
a_min = a_copy[0]
b_min = b_copy[0]
min = a_min + b_min
totals = [min]
for list in coupon:
    tmp = a_price[list[0] - 1] + b_price[list[1] - 1] - list[2]
    totals.append(tmp)

totals.sort()
ans = totals[0]

print(ans)

Solution (Python):
import sys
from collections import deque

import math

def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    ans = 0
    flag = True
    for rep in discount:
        pay = a[rep[0]-1] + b[rep[1]-1] - rep[2]
        if flag:
            ans = pay
            flag = False
        else:
            ans = min(ans,pay)
    
    ans = min(ans,min(a)+min(b))
    print(ans)
    return

if __name__=='__main__':
    A,B,M = IL()
    a = list(IL())
    b = list(IL())
    discount = [list(IL()) for _ in range(M)]
    solve()

Solution (Python):
A, B, M = map(int, input().split())
a = [int(a) for a in input().split()]
b = [int(b) for b in 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())

all_prices = []
for x, y, c in zip(X, Y, C):
        all_prices.append(a[x-1] + b[y-1] - c)

prices = [min(a) + min(b), min(all_prices)]

print(min(prices))

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())
re = list(map(int, input().split()))
de = list(map(int, input().split()))
mre = min(re)
mde = min(re)
list1 = []
for i in range(m):
  x, y, c = map(int, input().split())
  price = re[x-1] + de[y-1] -c
  list1.append(price)
mlist = min(list1)
m1 = mre + mde

if m1 < mlist:
  print(m1)
else:
  print(mlist)

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):
    x0,y0,c0=map(int,input().split())
    x.append(x0)
    y.append(y0)
    c.append(c0)

ans = min(a) + min(b)

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

print(ans)

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

min_num=min(a_list)+min(b_list)
for i in range(m):
  x,y,c=map(int,input().split())
  num = a_list[x-1] + b_list[y-1] -c
  min_num=min(min_num,num)
  
print(min_num)

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

minPrice = min(price_a) + min(price_b)

for i in range(m):
	x,y,c = map(int,input().split())
	price = price_a[x-1] + price_b[y-1] -c
	if price < minPrice:
		minPrice = price

print(minPrice)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, M =map(int, readline().split())
a = np.array(readline().split(), np.int64)
b = np.array(readline().split(), np.int64)

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

for i in range(M):
  w = list(map(int, input().split()))
  new = a[w[0]-1] + b[w[1]-1] - w[2]
  ans = min(ans, new)
print(ans)

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

alis = list(map(int, input().split()))
blis = list(map(int, input().split()))

ans = min(alis)+min(blis)
for i in range(m):
    x,y,c = map(int, input().split())
    t = alis[x-1] + blis[y-1] -c

    ans = min(ans, t)

print(ans)

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


for n in range(M):
    m.append([int(s) for s in input().split()])

minValue = min(a) + min(b)

for i in range(M):
    discountPrice = a[m[i][0] - 1] + b[m[i][1] - 1] - m[i][2]
    if discountPrice  < minValue:
        minValue = discountPrice

print(minValue)

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 m in range(M)]
ans = min(a)+min(b)
for m in range(M):
  tmp = a[XYC[m][0]-1]+b[XYC[m][1]-1]-XYC[m][2]
  ans = min(tmp, ans)
print(ans)

Solution (Python):
'''
Created on 2020/08/20

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  
  A,B,M=map(int,pin().split())
  a=list(map(int,pin().split()))
  b=list(map(int,pin().split()))
  
  ans=min(a)+min(b)
  
  for _ in [0]*M:
    x,y,c=map(int,pin().split())
    t=a[x-1]+b[y-1]-c 
    if t<ans:
      ans=t 
  print(ans)
  return 

main()

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

lst=[]
for i in range(m):
  x,y,z=list(map(int,input().split()))
  lst.append([x,y,z])
  
ans=min(aa)+min(bb)

for i in lst:
  ans=min(ans,aa[i[0]-1]+bb[i[1]-1]-i[2])
  
  
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()]
xyc=[[int(i)for i in input().split()]for j in range(M)]
res=min(a)+min(b)
for x,y,c in xyc:
    tmp=a[x-1]+b[y-1]-c
    res=min(res,tmp)
print(res)

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

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

Solution (Python):
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(m)]
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, N = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
l.append(min(a) + min(b))
for _ in range(N):
  aq, bq, d = map(int, input().split())
  l.append( a[aq-1] + b[bq-1] - d )
print(min(l))

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

A = int(lst1[0])
B = int(lst1[1])
M = int(lst1[2])

list_A = input().split()
list_B = input().split()

for i in range(A):
   list_A[i] = int(list_A[i])

for i in range(B):
   list_B[i] = int(list_B[i])

result = min(list_A) + min(list_B)

list_M = []

for i in range(M):
   lst2 = input().split()
   n = list_A[int(lst2[0]) - 1] + list_B[int(lst2[1]) - 1] - int(lst2[2])
   if n < result:
      result = n

print(result)