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()))
nedan = set()
nedan.add(min(a) + min(b))
for i in range(M):
    j, k, l = map(int, input().split())
    nedan.add(a[j - 1] + b[k - 1] - l)
print(min(nedan))

Solution (Python):
a,b,m=map(int, input().split(" "))
alist=list(map(int, input().split(" ")))
blist=list(map(int, input().split(" ")))

qlist=[list(map(int,list(input().split(" ")))) for i in range(m)]

ans = min(alist) + min(blist)

for q in qlist:
  ans = min([alist[q[0]-1] + blist[q[1]-1] - q[2],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())
  val = a[x-1] + b[y-1] - c
  ans = min(ans, val)
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):
a,b,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=min(arr1)+min(arr2)
for _ in range(m):
  x,y,c=map(int,input().split())
  tmp=arr1[x-1]+arr2[y-1]-c
  ans=min(ans,tmp)
print(ans)

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

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

_, _, m = map(int, input().split())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
ans = min(a) + min(b)
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1; y -= 1
    val = a[x] + b[y] - c
    if val < ans:
        ans = val

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

aMIN = min(a)
bMIN = min(b)

MIN = aMIN + bMIN

for k in data:
    MIN = min(MIN, a[k[0]-1]+b[k[1]-1]-k[2])


print(MIN)

Solution (Python):
num = [int(n) for n in input().split(" ")]
A, B, M = num[0], num[1], num[2]

a = [int(n) for n in input().split(" ")]
b = [int(n) for n in input().split(" ")]

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


temp_min = min(a) + min(b)

for d in data:
    total = a[d[0]-1] + b[d[1]-1] - d[2]
    if temp_min > total:
        temp_min = total

print(temp_min)

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

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 = []
for i in range(M):
  ans.append(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2])
mi=min(a)+min(b)
print(min(min(ans),mi))

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

min_m = float('inf')
for ai, bi, c in [map(int, input().split()) for _ in range(m)]:
	if min_m > A[ai-1] + B[bi-1] - c:
		min_m = A[ai-1] + B[bi-1] - c
print(min(min(A)+min(B),min_m))

Solution (Python):
lines = []
line = input()
s = line.split(' ')
entries = int(s[2]) + 2
for i in range(entries+1):
    lines.append(line.split(' '))
    if i < entries:
        line = input()

discounts = []
for idx, line in enumerate(lines):
    if idx == 0:
        A = line[0]
        B = line[1]
        M = line[2]
    elif idx == 1:
        refrigerators = line
    elif idx == 2:
        microwaves = line
    else:
        discounts.append(line)

ref_reg = int(10 ** 5)
for r in refrigerators:
    reg = int(r)
    if ref_reg > reg:
        ref_reg = reg

ref_mic = int(10 ** 5)
for m in microwaves:
    mic = int(m)
    if ref_mic > mic:
        ref_mic = mic

ref_min = ref_reg + ref_mic
for discount in discounts:
     d = int(refrigerators[int(discount[0])-1]) + int(microwaves[int(discount[1])-1]) - int(discount[2])
     if d < ref_min:
         ref_min = d       
         
print(ref_min)

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


min_m = float('inf')
for ai, bi, c in [map(int, input().split()) for _ in range(m)]:
	if min_m > A[ai-1] + B[bi-1] - c:
		min_m = A[ai-1] + B[bi-1] - c

print(min(min(A)+min(B),min_m))

Solution (Python):

costA = []
costB = []


A,B,M = map(int,input().split()) 
x = [[] for i in range(M)]
y = [[] for i in range(M)]
c = [[] for i in range(M)]
costA = input().split()
costB = input().split()
for i in range(M):
  x[i],y[i],c[i] = map(int,input().split()) 
                                            
                                            
mincostA = int(costA[0])
for j in range(A):
  if int(costA[j]) < mincostA:
    mincostA = int(costA[j])

mincostB = int(costB[0])
for k in range(B):
  if int(costB[k]) < mincostB:
    mincostB = int(costB[k])

teika = mincostA + mincostB

for l in range(M):
  ind1 = x[l] - 1
  out1 = int(costA[ind1]) 
  ind2 = y[l] - 1
  out2 = int(costB[ind2])
  if (out1 + out2 - int(c[l])) < teika:
    teika = (out1 + out2 - int(c[l]))

print(teika)

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

print(ans)

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

La = [int(_) for _  in input().split()]
Lb = [int(_) for _ in input().split()]
Lm = [[int(_) for _ in input().split()] for _ in range(M)]

ans = min(La) + min(Lb)
for x, y, c in Lm:
    ans = min(ans, La[x-1] + Lb[y-1] - c)
print(ans)

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

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

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

minimum=min(alist)+min(blist)

for i in range(m):
    tempx,tempy,tempc=mlist[i]
    discountsum=alist[tempx-1]+blist[tempy-1]-tempc
    if  discountsum < minimum:
        minimum=discountsum

print(minimum)

Solution (Python):


A, B, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

ans = 1000000
for i 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

if ans > min(a) + min(b):
    ans = min(a) + min(b)

print(ans)

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

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

cost=min(alist)+min(blist)

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

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

ans = min(a) + min(b)
for 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())
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
discounts = [list(map(int, input().split())) for i in range(M)]
ans_candidate = min(price_A) + min(price_B)

for discount in discounts:
    tmp_ans = price_A[discount[0]-1] + price_B[discount[1]-1] - discount[2]
    if tmp_ans <= ans_candidate:
        ans_candidate = tmp_ans

print(ans_candidate)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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


print(ret)

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

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ 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):
abm = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]

xyc = []
for i in range(abm[2]):
  xyc.append([int(i) for i in input().split(" ")])

minDiscount = float("inf")
for i in xyc:
  minDiscount = min(a[i[0]-1] + b[i[1]-1] - i[2], minDiscount)

minNotDiscount = min(a) + min(b)

print(min(minDiscount, minNotDiscount))

Solution (Python):
def o():return list(map(int,input().split()))
n=o();a=o();b=o()
c=min(a)+min(b)
for i in range(n[2]):
  x=o()
  c=min(c,a[x[0]-1]+b[x[1]-1]-x[2])
print(c)

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

Solution (Python):
A, B, M = map(int, input().split())
*a, = map(int, input().split())
*b, = map(int, input().split())
a_s = sorted(a)
b_s = sorted(b)
min_v = a_s[0] + b_s[0]
for _ in range(M):
    x, y, c = map(int, input().split())
    min_v = min(min_v, a[x-1] + b[y-1] - c, )
print(min_v)

Solution (Python):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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



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

Solution (Python):
A, B, M = [int(i) for i in input().split()]
ref = [int(i) for i in input().split()]
mic = [int(i) for i in input().split()]
cheap = min(ref) + min(mic)
for i in range(M):
  cp = [int(j) for j in input().split()]
  cheap = min([cheap, ref[cp[0]-1] + mic[cp[1]-1] - cp[2]])
print(cheap)

Solution (Python):
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = [0] * m
Y = [0] * m
C = [0] * m
for i in range(m):
    X[i], Y[i], C[i] = map(int, input().split())
cost = min(A) + min(B)
for i in range(m):
    cost = min(cost, A[X[i] - 1] + B[Y[i] - 1] - C[i])
print(cost)

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

min_ = min(A)+min(B)

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

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

ma = min(a)
mb = min(b)

cost = ma + mb

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

print(cost)

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

A,B,M=map(int,readline().split())
a=list(map(int,readline().split()))
b=list(map(int,readline().split()))

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

Solution (Python):
import math
import heapq
import bisect
from collections import defaultdict, Counter, deque
import sys

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def update_all(self):
        n = len(self.par)
        for i in range(n):
            self.par[i] = self.find(i)

def main():
    a,b,m = getList()
    anums = getList()
    bnums = getList()
    ans = min(anums) + min(bnums)
    for i in range(m):
        x,y,c = getList()
        tmp = anums[x-1] + bnums[y-1] - c
        if ans > tmp:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

"""
10
203941992 742164984
670850202 743524472
687298546 744891559
676493045 744182895
385467254 742631752
740505911 744926772
425723256 743348462
225362543 742332848
399450535 742706299
563528474 743419738
"""

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 i in range(M):
    cnt1, cnt2, cnt3 = map(int, input().split())
    x.append(cnt1)
    y.append(cnt2)
    c.append(cnt3)
ans = 10**9+7

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

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

num = min(a) + min(b)
if num < ans:
    ans = num

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

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):
import sys
input = sys.stdin.buffer.readline







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 i 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=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

ans=99999999999
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 copy
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
q=[list(map(int,input().split())) for _ in range(M)]
a1=copy.deepcopy(a)
b1=copy.deepcopy(b)
a1.sort()
b1.sort()
min=a1[0]+b1[0]
ca=0
for i in range(M):
 try:
  ca=a[q[i][0]-1]+b[q[i][1]-1]-q[i][2]
 except:
  ca=float("inf")
 if ca<min:
  min=ca
print(min)

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

x = 0
y = 1
c = 2

price = []

for i in range(m):
    price.append(a[xyc[i][x]-1] + b[xyc[i][y]-1] - xyc[i][c])

print(min(min(price), 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()))

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

disc = [0] * M
for i in range(M):
  disc[i] = a[x[i]-1] + b[y[i]-1] - c[i]

D = min(a) + min(b)

print(min(min(disc), D))

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

a.sort()
b.sort()

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

print (ans)

Solution (Python):
res = -1
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
amin = 100000
bmin = 100000
cmin = amin + bmin
for i in a:
  if amin > i:
    amin = i
for i in b:
  if bmin > i:
    bmin = i
res = amin + bmin
for i in range(M):
  xi,yi,ci = list(map(int,input().split()))
  c = a[xi-1] + b[yi-1] - ci
  if cmin > c:
    cmin = c

if res > cmin:
  print(cmin)
else:
  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)
X = []
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()))
T = [tuple(map(int, input().split())) for _ in range(M)]

ans = min(a) + min(b)

for t in T:
    ans = min(ans, a[t[0] - 1] + b[t[1] - 1] - t[2])

print(ans)

Solution (Python):
a,b,m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(m)]

da = {}
for i in range(a):
    da[i+1] = al[i]
db = {}
for i in range(b):
    db[i+1] = bl[i]

res = min(al)+min(bl)
for x,y,c in xyc:
    res = min(res, da[x]+db[y]-c)

print(res)

Solution (Python):
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

A,B,M=input_int_list()
a_list=input_int_list()
b_list=input_int_list()
discounts=[input_int_list() for i in range(M)]

min_without_discount=min(a_list)+min(b_list)

set_price_with_discount=[a_list[di[0]-1]+b_list[di[1]-1]-di[2] for di in discounts]
min_discounted=min(set_price_with_discount)
print(min(min_discounted,min_without_discount))

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 = 10**9
for x,y,c in XYC:
    res = min(res,a[x-1]+b[y-1]-c)
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()))
mn = min(a) + min(b)
for _ in range(m):
  xi,yi,ci = map(int,input().split())
  d = a[xi-1] + b[yi-1] - ci 
  if d < mn:
    mn = d
print(mn)

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

Solution (Python):
A,B,M = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]
B_list = [int(y) for y in input().split()]
discount = []
min = 200000
for _ in range(M):
  case = [int(x) for x in input().split()]
  discount.append(case)
 
min_a = sorted(A_list)[0]
min_b = sorted(B_list)[0]
 
for i in range(M):
  temp = A_list[discount[i][0]-1] + B_list[discount[i][1]-1] - discount[i][2]
  if temp < min:
    min = temp
    
if min_a + min_b > min:
  print(min)
else:
  print(min_a + min_b)

Solution (Python):
A,B,M = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]
B_list = [int(y) for y in input().split()]
discount = []
min = 1000000
for _ in range(M):
  case = [int(x) for x in input().split()]
  discount.append(case)
 
min_a = sorted(A_list)[0]
min_b = sorted(B_list)[0]
 
for i in range(M):
  temp = A_list[discount[i][0]-1] + B_list[discount[i][1]-1] - discount[i][2]
  if temp < min:
    min = temp
    
if min_a + min_b > min:
  print(min)
else:
  print(min_a + min_b)

Solution (Python):
def b_nice_shopping():
    A, B, M = [int(i) for i in input().split()]
    refrigerator = [int(i) for i in input().split()]
    microwave = [int(i) for i in input().split()]
    discount_ticket = [[int(i) for i in input().split()] for j in range(M)]

    
    ans = min(refrigerator) + min(microwave)
    for x, y, c in discount_ticket:
        ans = min(ans, refrigerator[x - 1] + microwave[y - 1] - c)
    return ans

print(b_nice_shopping())

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

a_min = min(As)
b_min = min(Bs)

best_sum = a_min+b_min
coupons_sums = []
for l in coupons:
    coupons_sums.append(As[l[0]-1] + Bs[l[1]-1] - l[2])
    
for coupons_sum in coupons_sums:
    if best_sum > coupons_sum:
        best_sum = coupons_sum

print(best_sum)

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

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

ans = min(A) + min(B)
for x, y, c in XYC:
    cost = A[x - 1] + B[y - 1] - 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()))
AA=sorted(A)
BB=sorted(B)
ans=AA[0]+BB[0]
for i in range(m):
  x,y,c=map(int,input().split())
  d=A[x-1]+B[y-1]-c
  if d<ans:
    ans=d
print(ans)

Solution (Python):
if __name__ == '__main__':
    (A, B, M) = tuple(map(int, input().split()))
    rf_prices = list(map(int, input().split()))
    rg_prices = list(map(int, input().split()))
    d_tickets = [list(map(int, input().split())) for _ in range(M)]
    min_with_ticket = min([rf_prices[t[0]-1]+rg_prices[t[1]-1]-t[2] for t in d_tickets])
    min_with_none_ticket = min(rf_prices)+min(rg_prices)
    print(min(min_with_none_ticket, min_with_ticket))

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

Solution (Python):
A, B, M = map(int, input().split(' '))
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
min = 10000000
for i in range(M):
    x, y, c = map(int, input().split(' '))
    price = a[x - 1] + b[y - 1] - c
    if price < min:
        min = price
minA = minB = 1000000
for e in a:
    if e < minA:
        minA = e
for e in b:
    if e < minB:
        minB = e

if minA + minB < min:
    print(minA + minB)
else:
    print(min)

Solution (Python):



def main():
    A,B,M = list(map(int, input().split(' ')))

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


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

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

Solution (Python):
A,B,M = map(int, input().split(' '))
priceA = list(map(int, input().split(' ')))
priceB = list(map(int, input().split(' ')))
minPrice = min(priceA) + min(priceB)

for i in range(M):
    ai,bi,discount = list(map(int, input().split(' ')))
    sum = (priceA[ai-1] + priceB[bi-1] - discount)
    if minPrice > sum:
      minPrice = sum
else:      
    print(minPrice)

Solution (Python):
import numpy as np

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

num = min(a) + min(b)

for _ in range(M):
    m1,m2,m3 = map(int,input().split())
    res = a[m1-1]+b[m2-1] - m3
    num = min(num,res)

print(num)

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):
import numpy as np

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

num = int(min(a)) + int(min(b))

for _ in range(M):
    m1,m2,m3 = map(int,input().split())
    res = int(a[m1-1])+int(b[m2-1]) - m3
    num = min(num,res)

print(num)

Solution (Python):
a,b,m,*L=map(int,open(0).read().split());K=L[a+b:];I=L[a:a+b]
print(min(min(I)+min(L[:a]),min(-z+L[x-1]+I[y-1]for x,y,z in zip(*[iter(K)]*3))))

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

res=min(Ai)+min(Bi)
for j in range(M):
  s=list(map(int,input().split()))
  if Ai[s[0]-1]+Bi[s[1]-1]-s[2]<res:
    res=Ai[s[0]-1]+Bi[s[1]-1]-s[2]
print(res)

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

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

ans=min(a)+min(b)
for i in range(m):
    ans=min(ans,a[x[i][0]-1]+b[x[i][1]-1]-x[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()))
a1=sorted(a)
b1=sorted(b)
mini=a1[0]+b1[0]
for i in range(M):
    x,y,z=map(int,input().split())
    price=a[x-1]+b[y-1]-z
    if mini>price:
        mini=price
print(mini)