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

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b,m=MI()
    aa=LI()
    bb=LI()
    ans=min(aa)+min(bb)
    for _ in range(m):
        x,y,c=MI()
        x,y=x-1,y-1
        ans=min(ans,aa[x]+bb[y]-c)
    print(ans)

main()

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):
    x,y,c=map(int,input().split())
    XYC.append((x-1,y-1,c))
ans=min(A)+min(B)
for x,y,c in XYC:
    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())
    t=a[x-1]+b[y-1]-c
    if t<ans:
        ans=t
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 _ in range(M):
    x,y,c=map(int,input().split())
    xyc.append([x,y,c])
mi=min(a)+min(b)
for i in range(M):
    e=xyc[i][0]-1
    f=xyc[i][1]-1
    g=xyc[i][2]
    h=a[e]+b[f]-g
    mi =min(mi,h)
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())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

t = []
for i in range(m):
    x, y, c = map(int, input().split())
    t.append(al[x-1]+bl[y-1]-c)
a_min = min(al)
b_min = min(bl)
t.append(a_min+b_min)

print(min(t))

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

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

Solution (Python):
_, _, 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):
  xi, yi, ci = map(int, input().split())
  px = a[xi-1] + b[yi-1] - ci
  if px < ans:
    ans = px

print(ans)

Solution (Python):
def solve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    x, y, c = [0] * M, [0] * M, [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)


if __name__ == '__main__':
    solve()

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

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

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


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,m = LI()
A = LI()
B = LI()
xyc = [LI() 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())
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(j) for j in input().split()]
b=[int(j) for j in input().split()]

ans=min(a)+min(b)
for i in range(m):
    x,y,c=[int(j) for j in 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()))

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

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

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)]
result = [min(a)+min(b)]
for x, y, c in xyc:
    result.append(a[x-1]+b[y-1]-c)
print(min(result))

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 -= 1
    y -= 1
    p = a[x] + b[y] - c
    ans = min(ans, p)

print(ans)

Solution (Python):
def main():
    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 = min(A) + min(B)
    for i in range(M):
        x, y, c = (int(i) for i in input().split())
        cur = A[x-1] + B[y-1] - c
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys


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 = 10**9+7

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

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

Solution (Python):
a, b, m = [ int(v) for v in input().split() ]
a_list = [ int(v) for v in input().split() ]
b_list = [ int(v) for v in input().split() ]
ans_list = []
for i in range(m):
    x, y, c = [ int(v) for v in input().split() ]
    ans_list.append(a_list[x - 1] + b_list[y - 1] - c)
a_list.sort()
b_list.sort()
ans_list.append(a_list[0] + b_list[0])
print(min(ans_list))

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

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

min_pr = min(A) + min(B)

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

    price = A[x-1] + B[y-1] - c
    min_pr = min(min_pr, price)

print(min_pr)

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

A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
xycs = [tuple(map(int, input().split())) for _ in range(M)]

ans = min(As) + min(Bs)
for x, y, c in xycs:
    x, y = x-1, y-1
    cost = As[x] + Bs[y] - c

    ans = min(ans, cost)

print(ans)

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

Solution (Python):
def examA():
    S = SI()
    if len(S)%2==1:
        print("No")
        return
    for i in range(len(S)//2):
        if S[i*2:i*2+2]!="hi":
            print("No")
            return
    print("Yes")
    return

def examB():
    a, b, M = LI()
    A = LI()
    B = LI()
    D = [LI()for _ in range(M)]
    ans = min(A) + min(B)
    for x,y,c in D:
        cur = A[x-1]+B[y-1]-c
        ans = min(ans,cur)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

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

Solution (Python):
A, B, M = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
coupons = [tuple(map(int, input().split())) for _ in range(M)]
ans = min(A) + min(B)
for x, y, c in coupons:
    ans = min(ans, A[x-1]+B[y-1]-c)
print(ans)

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

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

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

ans = min(a) + min(b)

for x, y, c in xyc:
    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()))

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

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

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

ans=float('inf')
ans=min(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):
import sys
input = sys.stdin.readline

lA, lB, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
XYZ = [list(map(int, input().split())) for _ in range(M)]

ans = min(A) + min(B)
dic = {}
for x, y, c in XYZ:
    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 = []
for _ in range(M):
	x, y, c = map(int, input().split())
	m_list.append((x, y, c))

total = min(a_list) + min(b_list)

for x, y, c in m_list:
	pay = a_list[x - 1] + b_list[y - 1] - c
	if pay < total:
		total = pay

print(total)

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

Solution (Python):
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
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):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return input().split()
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    a, b, m = LI()
    a = LI()
    b = LI()
    xym = LIR(m)
    ans = min(a) + min(b)
    for x, y, m in xym:
        ans = min(ans, a[x - 1] + b[y - 1] - m)
    print(ans)
    return



if __name__ == '__main__':
    solve()

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(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [tuple(map(int, input().split())) for _ in range(M)]

w_mn = 10**9
for x,y,c in xyc:
    w_mn = min(w_mn, a[x-1] + b[y-1] - c)

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

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

ref = list(map(int,input().split()))
mic = list(map(int,input().split()))

ans = min(ref)+min(mic)


for i in range(m):
    x,y,c = map(int,input().split())
    x-=1
    y-=1

    if ref[x]+mic[y]-c < ans:
        ans = ref[x]+mic[y]-c

print(ans)

Solution (Python):
from sys import stdin
A,B,m = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
mina = min(a)
minb = min(b)
goukei = min(a)+min(b)
for i,j,k in li:
    goukei = min(goukei,a[i-1]+b[j-1]-k)
print(goukei)

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

print(ans)

Solution (Python):
A,B,M = [int(zz) for zz in input().split()]
lia = [int(zz) for zz in input().split()]
lib = [int(zz) for zz in input().split()]

ans = min(lia)+min(lib)
for _ in range(M):
    x,y,c = [int(zz) for zz in input().split()]
    ans = min(ans,lia[x-1]+lib[y-1]-c)

print(ans)

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

INF = 10 ** 18

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

answer = INF
for x, y, c in xyc:
    answer = min(answer, a[x] + b[y] - c)

a.sort()
b.sort()
answer = min(answer, a[0] + b[0])

print(answer)

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

ans = 10**10

for i in range(M):
	x,y,c = list(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

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



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read






p,q,m = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

ans = min(a)+min(b)

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

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

Solution (Python):

from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    a,b,m = mi()
    alist = li()
    blist = li()
    ans = min(alist)+min(blist)
    for i in range(m):
        x,y,c = mi()
        ans = min(ans,alist[x-1]+blist[y-1]-c)
    print(ans)




main()

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

MIN=min(A)+min(B)

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

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 = xyc[i][0] - 1
    y = xyc[i][1] - 1
    c = xyc[i][2]

    ans = min(ans, a[x] + b[y] - c)

print(ans)

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

for i,j,k in l:
    check = la[i-1]+lb[j-1]-k
    ans = min(ans,check)
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

A,B,m = inpl()
a = inpl()
b = inpl()
xyc = [inpl() for i in range(m)]
res = INF
for i in range(m):
    x,y,c = xyc[i]
    x -= 1; y -= 1
    tmp = a[x] + b[y] - c
    res = min(res, tmp)
res = min(res, min(a)+min(b))
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())
    v = a[x - 1] + b[y - 1] - c
    ans = min(ans, v)
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(A[x-1]+B[y-1]-c,ans)
print(ans)

Solution (Python):
a, b, m = map(int, input().split())
aa = [int(x) for x in input().split()]
bb = [int(x) for x in input().split()]
ans = min(aa)+min(bb)
for i in range(m):
  x, y, c = map(int, input().split())
  key = aa[x-1]+bb[y-1]-c
  if key < ans:
    ans = key
print(ans)

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

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

res = min(a) + min(b)
for x, y, c in L:
    tres = a[x - 1] + b[y - 1] - c
    res = min(res, tres)
print(res)

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

wari = []
for i in range(M):
    t = list(map(int, input().split()))
    wari.append([t[0]-1, t[1]-1, t[2]])



r = []

for x, y, c in wari:
    p = a[x] + b[y] - c
    r.append(p)
r.append(min(a)+min(b))



print(min(r))

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

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

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    A,B,M = inpm()
    a = inpl()
    b = inpl()
    ans = 10**20
    for _ in range(M):
        w,e,r = inpm()
        ans = min(ans,a[w-1]+b[e-1]-r)
    a.sort()
    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 = float("inf")
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()))
xyc = [list(map(int, input().split())) for _ in range(M)]

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

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
a,b,m = map(int,input().split())
als = list(map(int,input().split()))
bls = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for i in range(m)]
ans = min(als)+min(bls)
for x,y,c in xyc:
  ans = min(ans,als[x-1]+bls[y-1]-c)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



class UnionFindEx:
    def __init__(self, size):
        
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    
        self.roots[r2] = r1
        return True

def main():
    A,B,M = mis()
    a = lmis()
    b = lmis()
    ans = min(a) + min(b)
    for _ in range(M):
        x, y, c = mis()
        x -= 1
        y -= 1
        ans = min(ans, a[x]+b[y]-c)
    print(ans)


main()

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    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:
        tmp = a[x - 1] + b[y - 1] - c
        ans = min(ans, tmp)

    print(ans)



if __name__ == '__main__':
    main()

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()))
C = [list(map(int,input().split())) for i 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):
import sys
input = sys.stdin.readline

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

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=min(a)+min(b)
for i in range(M):
    x,y,c=map(int,input().split())
    t=a[x-1]+b[y-1]-c
    if m>t:
        m=t
print(m)