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):
def main():
    
    a,b,m= map(int, input().split())
    l1= list(map(int, input().split()))
    l2= list(map(int, input().split()))
    mi=min(l1)+min(l2)
    for i in range(m):
        p, q, r = map(int, input().split())
        cal=l1[p-1]+l2[q-1]-r
        mi=min(mi,cal)
    print(mi)
    return
main()

Solution (Python):


def main():
    a, b, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = [list(map(int, input().split())) for _ in range(m)]

    cost = min(a_list) + min(b_list)

    for i in range(m):
        discount = a_list[c_list[i][0] - 1] + b_list[c_list[i][1] - 1] - c_list[i][2]
        if cost > discount:
            cost = discount

    print(cost)

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()))
m = [input().split() for _ in range(M)]
price = []
price.append(int(min(a)) +int(min(b)))
for i in range(M):
    x = a[int(m[i][0])-1] + b[int(m[i][1])-1] - int(m[i][2])
    price.append(x)
print(min(price))

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

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


min_price_wo_waribiki = min(a) + min(b)


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


min_price = min(min_price_wo_waribiki, min_price_w_waribiki)
print(min_price)

Solution (Python):
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
mi = min(a) + min(b)

for i in range(M):
  c1, c2, c3 = [int(j) for j in input().split()]
  m =  a[c1-1] + b[c2-1] - c3
  if mi > m:
    mi = m

print(mi)

Solution (Python):
aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
  x1, y1, c1 = list(map(int,input().split()))
  x.append(x1)
  y.append(y1)
  c.append(c1)

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

price_min=float("INF")
for ticket in tickets:
    price = A[ticket[0]-1] + B[ticket[1]-1] - ticket[2]
    price_min = price if price_min>price else price_min


no_ticket=min(A)+min(B)
if price_min > no_ticket: price_min=no_ticket
print(price_min)

Solution (Python):
n_a, n_b, n_m=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
total = min(a) + min(b)
for i in range(n_m):
    x, y, c = list(map(int,input().split()))
    _total = a[x - 1] + b[y - 1] - c
    if _total < total:
        total = _total
print(total)

Solution (Python):


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

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):
    x, y, c = map(int, input().split())
    o_sum = l_a[x-1] + l_b[y-1] - c
    ans = min(o_sum, ans)

print(ans)

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

x = [None] * M
y = [None] * M
c = [None] * M

w = {}
m = min(a) + min(b)

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

print(m)

Solution (Python):

import numpy as np
A, B, M = map(int, input().split())
a_costs = list(map(int, input().split()))
b_costs = list(map(int, input().split()))
m_discounts = []
for m in range(M):
    tmp = list(map(int, input().split()))
    
    m_discounts.append(tmp)
ans = min(a_costs) + min(b_costs)


for m in m_discounts:
    tmp_ans = a_costs[m[0]-1] + b_costs[m[1]-1] - m[2]
    if (ans > tmp_ans):
        ans = tmp_ans
print(ans)

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

ans = min(a)+min(b)

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

Solution (Python):
A, B, M = map(int,input().split())
aArray = list(map(int,input().split()))
bArray = list(map(int,input().split()))
cArray = [[]] * M
for i in range(M):
    cArray[i] = (list(map(int,input().split())))
minV = min(aArray) + min(bArray)
for c in cArray:
    minV = min([minV, (aArray[c[0] - 1] + bArray[c[1] - 1] - c[2])])
print(minV)

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

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

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

m = min(a) + min(b)

for c in C:
  cost = a[c[0] - 1] + b[c[1] - 1] - c[2]
  if m >= cost:
    m = cost

print(m)

Solution (Python):
na,nb,M=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [[0 for i in range(3)] for j in range(M)]

s=min(A)+min(B)
t=0




for i in range(M):
	C[i][0],C[i][1],C[i][2] = map(int, input().split())



for j in range(M):
	
	t=A[C[j][0]-1]+B[C[j][1]-1]-C[j][2]
	if t<s:
		s=t

print(s)

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

min_ab = min(a_list) + min(b_list)
for i in range(m):
  x, y, c = map(int, input().split())
  if a < x or b < y:
    continue
  min_ab = min(a_list[x-1] + b_list[y-1] - c, min_ab)

print(min_ab)

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

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

print(value)

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

A_list = []
tmp = input().split()
for i in range(A):
  A_list.append(int(tmp[i]))
  
B_list = []
tmp = input().split()
for i in range(B):
  B_list.append(int(tmp[i]))
  
  
min_ = min(A_list)+min(B_list)

  
for i in range(M):
  tmp = input().split()
  tmp_goukei = A_list[int(tmp[0])-1]+B_list[int(tmp[1])-1]-int(tmp[2])
  if tmp_goukei < min_:
    min_ = tmp_goukei

print(min_)

Solution (Python):
A, B, M = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
ticket = []
for i in range(M):
    ticket.append(list(map(int, input().split())))
result = min(arr1) + min(arr2)
for i in ticket:
    x1 = i[0] - 1
    x2 = i[1] - 1
    temp = arr1[x1] + arr2[x2] - i[2]
    result = min(result, temp)
print(result)

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

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

tickets = []
for _ in range(m):
  tickets.append(map(int, input().split()))
  
m = min(A) + min(B)

for x, y, c in tickets:
  tmp_m = A[x-1] + B[y-1] - c
  if tmp_m < m:
    m = tmp_m
    
print(m)

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

a = input()
a = a.split(' ')
b = input()
b = b.split(' ')

x = []
y = []
c = []

for i in list(range(int(M))):
    tmp = input()
    tmp = tmp.split(' ')

    x.append(int(tmp[0]))
    y.append(int(tmp[1]))
    c.append(int(tmp[2]))

ans = []
tmp = int(min(a)) + int(min(b))
ans.append(tmp)

for i in list(range(int(M))):
    tmp = int(a[x[i]-1]) + int(b[y[i]-1]) - c[i]
    ans.append(tmp)

ans.sort()
print(ans[0])

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

minPrice = min(a) + min(b) 
price = 0

for x in range(len(c)):
    price = a[c[x][0]-1] + b[c[x][1]-1] - c[x][2]
    if minPrice > price:
        minPrice = price
    price = 0

print(minPrice)

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 i in range(M)]
MA=min(a)
MB=min(b)
MC=MA+MB
for i in range(M):
  if a[L[i][0]-1]+b[L[i][1]-1]-L[i][2]<MC:
    MC=a[L[i][0]-1]+b[L[i][1]-1]-L[i][2]
print(MC)

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):
    x, y, c = map(int, input().split())
    kaikei = a[x-1] + b[y-1] - c
    if kaikei < ans:
        ans = kaikei

print(ans)

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

Solution (Python):
A, B, M = map(int, input().split())
LA = [int(a) for a in input().split()]
LB = [int(b) for b in input().split()]
T = [[int(t) for t in input().split()] for _  in range(M)]
C = 10 ** 9
for i in range(M):
    C = min(LA[T[i][0]-1]+LB[T[i][1]-1]-T[i][2], C)
print(min(C, min(LA)+min(LB)))

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]"):
    result = min(a)+min(b)
    for i in range(M):
        result = min(result,a[x[i]-1]+b[y[i]-1]-c[i])
    print(max(0,result))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    M = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(A)]  
    b = [int(next(tokens)) for _ in range(B)]  
    x = [int()] * (M)  
    y = [int()] * (M)  
    c = [int()] * (M)  
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)

if __name__ == '__main__':
    main()

Solution (Python):
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(A)
D = sorted(B)
l = C[0] + D[0]
for i in range(m):
  x, y, c = map(int, input().split())
  k = A[x-1] + B[y-1] -c
  if l > k:
    l = k
print(l)

Solution (Python):



import sys

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

xn = []
yn = []
cn = []
for i in range(m):
    x, y, c = map(int, input().split())
    xn.append(x)
    yn.append(y)
    cn.append(c)








min_a = min(price_a)
min_b = min(price_b)
min_s = min_a + min_b


min_d_s = min_s
for i in range(m):
    
    s = price_a[xn[i] - 1] + price_b[yn[i] - 1] - cn[i]
    min_d_s = min(min_d_s, s)

print(min_d_s)

Solution (Python):
from sys import stdin

def main():

    input = stdin.readline

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

    a = [0] * A
    b = [0] * B

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

    min_price = min(a) + min(b)

    for _ in range(M):
        ticket = list(map(int,input().split()))
        price = a[ticket[0]-1] + b[ticket[1]-1] - ticket[2]

        min_price = min(min_price,price)

    print(min_price)


if __name__ == "__main__":
    main()

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

min_ab = min(a_list) + min(b_list)
for i in range(m):
  x, y, c = map(int, input().split())
  if a < x or b < y:
    continue
  min_ab = min(a_list[x-1] + b_list[y-1] - c, min_ab)

print(min_ab)

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

d=[0]*M
for i in range(0,M):
    d[i] = a[x[i]-1] + b[y[i]-1] - c[i]
a.sort()
b.sort()
d.sort()
print(min(a[0]+b[0],d[0]))

Solution (Python):
s = input().split()
a, b, m = int(s[0]), int(s[1]), int(s[2])

a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]

ans = min(a_list) + min(b_list)

for i in range(m):
    ss = input().split()
    temp = a_list[int(ss[0])-1] + b_list[int(ss[1])-1] - int(ss[2])
    if ans > temp:
        ans = temp

print(ans)

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

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

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
m = [list(map(int, input().split())) for _ in range(M)]

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

print(ans)

Solution (Python):
ABM = list(map(int, input().split()))
refrigerator = list(map(int, input().split()))
microwave = list(map(int, input().split()))

commonMin = min(refrigerator) + min(microwave)

discount = []

for i in range(ABM[2]):
    discount.append(list(map(int, input().split())))

min = 200000
tmp = 0
for i in range(len(discount)):
    dis = discount[i]
    tmp = refrigerator[dis[0] - 1] + microwave[dis[1] - 1] - dis[2]
    if (tmp < min):
        min = tmp

if (commonMin < min):
    print(commonMin)
else:
    print(min)

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

for i in range(M):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    c.append(int(inputs[2]))
price = min(a) + min(b)
for i in range(M):
    if(a[x[i]-1] + b[y[i]-1] - c[i] < price):
        price = a[x[i]-1] + b[y[i]-1] -  c[i]
print(price)

Solution (Python):
n = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cupon = [list(map(int,input().split())) for i in range(n[2])]

nasi = min(a) + min(b)
mai = [a[i[0] -1] + b[i[1] -1] - i[2] for i in cupon]
m = min(mai)
if nasi < m:
  print(nasi)
else:
  print(m)

Solution (Python):
from collections import deque

(A, B, M) = list(map(int, input().split()))
A_Price = list(map(int, input().split()))
B_Price = list(map(int, input().split()))
Coupon = [list(map(int, input().split())) for _ in range(M)]

tmp_min_price = min(A_Price) + min(B_Price)

discounted_Prices = deque()
for i in range(M):
    discounted_Prices.append(A_Price[Coupon[i][0] - 1] \
                             + B_Price[Coupon[i][1] - 1] \
                             - Coupon[i][2])

min_discounted_price = min(discounted_Prices)
print(min(min_discounted_price, tmp_min_price))

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    a, b, m = map(int, input().split())
    refrigerators = list(map(int, input().split()))
    microwaves = list(map(int, input().split()))
    tickets = [list(map(int, input().split())) for _ in range(m)]

    x_ret = min(refrigerators)
    y_ret = min(microwaves)
    ret = x_ret + y_ret
    for x, y, c in tickets:
        p = refrigerators[x - 1] + microwaves[y - 1] - c
        ret = min(ret, p)
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
A,B,M=map(int,input().split())
a=input().split()
a=[int(p) for p in a]
b=input().split()
b=[int(p) for p in b]
minv=min(a)+min(b)

for i in range(M):
    q=input().split()
    q=[int(p)for p in q]
    minv=min(minv,a[q[0]-1]+b[q[1]-1]-q[2])
    
print(minv)

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

m_l.sort(key=lambda x: x[2])
a_l_s = sorted(a_l)
b_l_s = sorted(b_l)
ans = a_l_s[0] + b_l_s[0]

for j in range(m):
    price = a_l[m_l[j][0]-1] + b_l[m_l[j][1]-1] - m_l[j][2]
    if price < ans:
        ans = price

print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

A,B,M = inpl()
aa = inpl()
bb = inpl()

ans = min(aa) + min(bb)

for _ in range(M):
    x,y,c = inpl()
    tmp = aa[x-1] + bb[y-1] - c
    ans = min(ans,tmp)


print(ans)

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

tmp=99999999

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

k=(min(al)+min(bl))

print(min(k,tmp))

Solution (Python):
a,b,m=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
ans=10**9
for i in range(m):
    x,y,c=map(int,input().split())
    if len(a)>=x and len(b)>=y:
        res=a[x-1]+b[y-1]-c
        ans=min(ans,res)
l=min(a)+min(b)
print(min(ans,l))

Solution (Python):
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    A, B, M = MI()
    a = LI()
    b = LI()
    xyc = LIR(M)
    
    m = min([a[i[0]-1] + b[i[1]-1] - i[2] for i in xyc])
    print(min([m, min(a)+min(b)]))

if __name__ == '__main__':
    main()

Solution (Python):
A, B, M = input().split(" ")
A, B, M = int(A), int(B), int(M)
a = input().split(" ")
b = input().split(" ")
a = list(map(int, a))
b = list(map(int, b))
amin = min(a)
bmin = min(b)
min_price = amin + bmin

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

print(min_price)

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

MIN = min(a) + min(b)
sum = 0
for _ in range(M):
    x, y ,c = [int(__) for __ in input().split()]
    tmp = a[x-1] + b[y-1] - c
    if tmp < MIN:
        MIN = tmp
print(MIN)

Solution (Python):
A, B, M = map(int, input().split())
a_price = list(map(int, input().split()))
b_price = list(map(int, input().split()))
coupon = [list(map(int, input().split())) for i in range(M)]



min = min(a_price) + min(b_price)


for cpn in coupon:
    idx_a = cpn[0]-1
    idx_b = cpn[1]-1
    total = a_price[idx_a] + b_price[idx_b] - cpn[2]
    if min > total:
        min = total

print(min)

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

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

    normal = min(a) + min(b)
    return min(normal, min(Y))

print(solve())

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

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

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

ticket = []

while M>0:
    ticket.append(tuple(map(int, input().split())))
    M -= 1

lowest = min(a)+min(b)

for ele in ticket:
    t = a[ele[0]-1] + b[ele[1]-1] - ele[2]
    if t < lowest:
        lowest = t
print(lowest)

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, M = MAP()
A_L = LIST()
B_L = LIST()

M_L = []
for i in range(M):
    tmp = LIST()
    M_L.append(tmp)

A_L_min = min(A_L)
B_L_min = min(B_L)
A_B_min_sum = A_L_min + B_L_min

ans = A_B_min_sum
for m in M_L:
    tmp = A_L[m[0]-1] + B_L[m[1]-1] - m[2]
    if tmp < ans:
        ans = tmp
print(ans)

Solution (Python):
abm=list(map(int, input().split())) 
a=list(map(int, input().split())) 
b=list(map(int, input().split())) 
answer=min(a)+min(b)
for i in range(abm[2]):
    xyc=list(map(int, input().split())) 
    answer00=a[xyc[0]-1]+b[xyc[1]-1]-xyc[2]
    if answer00<answer:
        answer=answer00
print(answer)

Solution (Python):
a,b,m = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_x = [list(map(int, input().split())) for _ in range(m)]

cheap_price = float("inf")
for i in lst_x:
    price = lst_A[i[0]-1] + lst_B[i[1]-1] - i[2]
    if price < cheap_price:
        cheap_price = price

price_wa = min(lst_A) + min(lst_B)

if cheap_price <= price_wa:
    print(cheap_price)
elif cheap_price > price_wa:
    print(price_wa)

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


cheap = a_s[0] + b_s[0]

for i in range(M):

    
    x, y, c = map(int, input().split())
    dis_cheap = a[x - 1] + b[y - 1] - c

    if cheap > dis_cheap:
        cheap = dis_cheap

print(cheap)

Solution (Python):

import sys
input = sys.stdin.buffer.readline

def inn(func=int):
    return list(map(func,input().split()))

def ins():
    return input().split()

an,bn,m = inn()
a = inn()
b = inn()

m_a = min(a)
m_b = min(b)
min_n = min(a)+min(b)

coupon = {}
for i in range(m):
    xi,yi,ci = inn()
    xi = xi-1
    yi = yi-1
    sum_vou = a[xi]+b[yi]-ci
    if sum_vou < min_n:
        min_n = sum_vou

print(min_n)


'''
for i in range(m):
    xi,yi,ci = inn()
    xi = xi-1
    yi = yi-1
    if not (xi,yi) in coupon.keys():
        coupon[(xi,yi)] = ci
    else:
        if coupon[(xi,yi)] < ci:
            coupon[(xi,yi)] = ci
'''

Solution (Python):


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

list1 =[]
for n in range(ABM[2]):
    list1.append(list(map(int,input().split())))

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

min1 = amin + bmin

minlist = []

for i in range(ABM[2]):
    minlist.append(a[list1[i][0]-1] + b[list1[i][1]-1] - list1[i][2])


min2 = min(minlist)


if(min1 > min2):
    min1 = min2

print(min1)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = list()
y = list()
c = list()
for i in range(M):
	_x, _y, _c = map(int, input().split())
	x.append(_x-1)
	y.append(_y-1)
	c.append(_c)



price_no_discount = min(a) + min(b)


price_with_discount = list()
for i in range(M):
	price_with_discount.append(a[x[i]] + b[y[i]] - c[i])

price_with_discount = min(price_with_discount)

if price_no_discount < price_with_discount:
	print(price_no_discount)
else:
	print(price_with_discount)

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

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

Solution (Python):
a,b,m=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
x=[]
y=[]
c=[]
for _ in range(m):
    x1,y1,c1=map(int,input().split())
    x.append(x1)
    y.append(y1)
    c.append(c1)

ans=300000
amin=min(alist)
bmin=min(blist)
if(ans>(amin+bmin)):
    ans=amin+bmin
else:
    pass

for i in range(m):
    cost=alist[x[i]-1]+blist[y[i]-1]-c[i]
    if(ans>cost):
        ans=cost
    else:
        continue
print(ans)

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

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

Solution (Python):
def resolve():
    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):
        xx, yy, cc = map(int, input().split())
        tmp = a[xx - 1] + b[yy - 1] - cc
        ans = min(ans, tmp)

    print(ans)


resolve()

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

minv = (10**5)*2
for _ in range(M):
    x, y, c = map(int, input().split())
    x = x - 1
    y = y - 1
    v = (a[x] + b[y]) - c
    if v < minv:
        minv = v

if min(a)+min(b) < minv:
    minv = min(a)+min(b)

print(minv)

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)
count = []
for m in range(M):
    x, y, c = map(int, input().split())
    price = a[x - 1] + b[y - 1] - c
    count.append(price)

if min(count) <= ans:
    print(min(count))
else:
    print(ans)

Solution (Python):
[A, B, M] = [int(i) for i in input().split()]
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
min_amount = min(a_list) + min(b_list)

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

Solution (Python):
a,b,m = map(int,input().split())
f = list(map(int,input().split()))
r = list(map(int,input().split()))
mn = min(f) + min(r)

for i in range(m):
    x,y,c = map(int,input().split())
    if f[x-1] + r[y-1] - c < mn:
        mn = f[x-1] + r[y-1] - c 
print(mn)

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 = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mini = 2*10**5
for i in range(M):
  num = list(map(int, input().split()))
  tmp = a[num[0]-1] + b[num[1]-1] - num[2]
  if tmp < mini:
    mini = tmp
mini = min(mini, min(a)+min(b))
      
print(mini)

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

Solution (Python):
na,nb,nm = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
TA = []
for i in range(nm):
    m1, m2, m3 = map(int,input().split())
    T = a[m1-1]+b[m2-1]-m3
    TA.append(T)
T = min(a) + min(b)
TA.append(T)
print(min(TA))