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()))
xyc = []

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

xyc.sort()

print(min(min(a)+min(b), xyc[0]))

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

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

ans = 100000000

for i in range(m):
    x,y,c = xyc[i]
    cost = A[x-1] + B[y-1] - c
    if ans > cost:
        ans = cost

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

print(ans)

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

Solution (Python):
def main():
    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 i in range(M)]
    minAB = min(Al) + min(Bl)
    now_min = minAB
    for m in xyc:
        s = Al[m[0]-1] + Bl[m[1]-1] - m[2]
        if s < now_min:
            now_min = s

    print(now_min)


if __name__ == "__main__":
    main()

Solution (Python):
def main(): 
    _, _, m = map(int,input().split())
    reizo = list(map(int,input().split()))
    renzi = list(map(int,input().split()))
    waribiki = [list(map(int,input().split())) for i in range(m)]

    min_cost = min(reizo) + min(renzi)

    for i in range(m):
        cost = reizo[waribiki[i][0]-1] + renzi[waribiki[i][1]-1] - waribiki[i][2]

        if cost < min_cost:
            min_cost = cost
    
    print(min_cost)


main()

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

def calc_money(x, y, c):
  return A_list[x-1] + B_list[y-1] - c

money = 10**7
for i in range(M):
  x, y, c = map(int, input().split())
  tmp_money = calc_money(x, y, c)
  if tmp_money < money:
    money=tmp_money
print(min(money,min(A_list)+ min(B_list)))

Solution (Python):
ans = []

number = input().split(" ")
A = int(number[0])
B = int(number[1])
M = int(number[2])
a = input().split(" ")
a = list(map(int, a))
b = input().split(" ")
b = list(map(int, b))

for i in range(M):
    dis = input().split(" ")
    x = int(a[int(dis[0])-1]) + int(b[int(dis[1])-1]) - int(dis[2])
    ans.append(x)
a.sort()
b.sort()
ans.append(int(a[0])+int(b[0]))
ans = list(map(int, ans))
ans.sort()
print(ans[0])

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, M = map(int, input().split())
    AA = tuple(map(int, input().split()))
    BB = tuple(map(int, input().split()))
    XYC = [tuple(map(int, input().split())) for _ in [0] * M]

    case0 = min(AA) + min(BB)
    case1 = case0
    for x, y, c in XYC:
        case1 = min(case1, AA[x-1] + BB[y-1] - c)
    print(case1)


main()

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

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

for _ in range(m):
    i, j, k = list(map(int, input().split()))
    p.append(a[i-1] + b[j-1] - k)
ppt = min(p)

if ans > ppt: ans = ppt

print(ans)

Solution (Python):


line1 = [int(x) for x in input().rstrip().split(" ")]
num_refrigeratores, num_microwaves, num_discount_tickets = line1[0], line1[1], line1[2]

ls_price_refrigeratores = [int(x) for x in input().rstrip().split(" ")]
ls_price_microwaves = [int(x) for x in input().rstrip().split(" ")]

price_min = min(ls_price_refrigeratores) + min(ls_price_microwaves)

for _ in range(num_discount_tickets):
    linen = [int(x) for x in input().rstrip().split(" ")]
    total_price = ls_price_refrigeratores[linen[0] - 1] + ls_price_microwaves[linen[1] - 1] - linen[2]
    if price_min > total_price:
        price_min = total_price

print(price_min)

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]"):
    min_no_coupon = sorted(a)[0] + sorted(b)[0]

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

    print(min(min_coupon, min_no_coupon))


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()))
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=min(a)+min(b)

for i 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):
class SetItem:
    def __init__(self, a, b, sub):
        self.a = a
        self.b = b
        self.sub = sub

    def get_total(self, a_list, b_list):
        a_value = a_list[self.a-1]
        b_value = b_list[self.b-1]
        return a_value + b_value - self.sub


a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
set_list = []
for _ in range(m):
    a, b, sub = map(int, input().split())
    set_item = SetItem(a, b, sub)
    set_list.append(set_item.get_total(a_list, b_list))

set_list.sort()
a_list.sort()
b_list.sort()
ans = a_list[0]+b_list[0] if a_list[0]+b_list[0] < set_list[0] else set_list[0]
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()))

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

ans = sorted(a_list)[0] + sorted(b_list)[0]

for discount in discount_list:
    tmp = a_list[discount[0]-1] + b_list[discount[1]-1] - discount[2]
    if ans > tmp:
        ans = tmp

print(ans)

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

ans=min(a)+min(b)

for i in range(M):
    c=list(map(int,input().split()))
    maybe_ans=a[c[0]-1]+b[c[1]-1]-c[2]
    if maybe_ans<ans:
        ans=maybe_ans
    else:
        pass

print(ans)

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

minSum = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    nowsum = a[x - 1] + b[y - 1] - c
    if nowsum < minSum:
        minSum = nowsum
print(minSum)

Solution (Python):
import numpy as np
A, B, M = map(int,input().split())
a = np.array([int(num) for num in input().split()])
a_min = np.min(a)

b = np.array([int(num) for num in input().split()])
b_min = np.min(b)
total_min= a_min + b_min

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

no_use = min(A)+min(B)
use=A[xyc[0][0]-1]+B[xyc[0][1]-1]-xyc[0][2]
for i in range(1,m):
    use = min(use,A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2])
print(min(no_use,use))

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

normal_min = min(a_list) + min(b_list)
for m_list_it in m_list:
    x, y, c = m_list_it[0], m_list_it[1], m_list_it[2]
    spe_min = a_list[x-1] + b_list[y-1] - c
    if spe_min < normal_min:
        normal_min = spe_min
print(normal_min)

Solution (Python):
A, B, M = input().split(" ")
M = int(M)
A_list = input().split(" ")
A_list = list(map(int, A_list))
B_list = input().split(" ")
B_list = list(map(int, B_list))
M_min = 99999999
for i in range(M):
    m = input().split(" ")
    m = list(map(int, m))
    if M_min > A_list[m[0]-1]+B_list[m[1]-1]-m[2]:
        M_min = A_list[m[0]-1]+B_list[m[1]-1]-m[2]
AB_min = min(A_list)+min(B_list)
if AB_min < M_min:
    print(AB_min)
else:
    print(M_min)

Solution (Python):
import math
import itertools
import statistics

A, B, 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):
    X, Y, Z = [int(j) for j in input().split()]
    x.append(X)
    y.append(Y)
    c.append(Z)

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

print(m)

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

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

Solution (Python):



import sys
from collections import deque as deq

An, Bn, Mn = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [list(map(int, input().split())) for i in range(Mn)]

mia = 10**5 + 10**5
for a in A:
    mia = a if a < mia else mia

mib = 10**5 + 10**5
for b in B:
    mib = b if b < mib else mib

R = mia + mib
for m in M:
    c = A[m[0] - 1] + B[m[1] - 1] - m[2]
    R = c if c < R else R

print(R)

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

mincomb = min(a) + min(b)

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

print(mincomb)

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


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


min_defo = min(a)+min(b)
min_discount = min(price)

print(min(min_defo,min_discount))

Solution (Python):
A, B, M = [int(i) for i in input().split()]
a_i = [int(i) for i in input().split()]
b_i = [int(i) for i in input().split()]
m_i = [[int(j) for j in input().split()] for i in range(M)]


min_v = 10**6
for m in m_i:
    v = a_i[m[0]-1] + b_i[m[1]-1] - m[2]

    if v < min_v:
        min_v = v

min_pair = min(a_i) + min(b_i)

if min_pair < min_v:
    min_v = min_pair

print(min_v)

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):
    j,k,l = map(int, input().split())
    x.append(j)
    y.append(k)
    c.append(l)
    

min_buy = min(a)+min(b)

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

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)]
x=[]
y=[]
c=[]
for i in range(M):
    x.append(L[i][0])
    y.append(L[i][1])
    c.append(L[i][2])
La=min(a)
Lb=min(b)
ans=La+Lb
for i in range(M):
    X=x[i]-1
    Y=y[i]-1
    han=a[X]+b[Y]-c[i]
    ans=min(han,ans)
print(ans)

Solution (Python):
a,b,m = map(int,input().split())
ap = list(map(int,input().split()))
bp = list(map(int,input().split()))
ls = []
for i in range(m):
    ls.append(list(map(int,input().split())))
m = min(ap)+min(bp)

for x,y,c in ls:
    if m > ap[x-1] + bp[y-1] - c:
        m =  ap[x-1] + bp[y-1] - c
print(m)

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

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

ans = min(reizouko_list) + min(densi_list)

for x, y, c in waribiki_list:
    value = reizouko_list[x - 1] + densi_list[y - 1] - c
    if ans > value:
        ans = value
print(ans)

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


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

print(mins)

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 i in range(M)]
ans=min(a)+min(b)
for i in range(M):
    ans=min((a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][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()] 
xyc = [input().split() for k in range(M)]
ans = []


for i in range(M):
  ans.append(a[int(xyc[i][0])-1] + b[int(xyc[i][1])-1]-int(xyc[i][2]))
  
ans.sort()
a.sort()
b.sort()
nomin=a[0]+b[0]

print(min(ans[0],nomin))

Solution (Python):

[A,B,M] = list(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())))


Nd = min(a) + min(b)


out = Nd
for i in range(M):
    d = a[xyc[i][0] -1] + b[xyc[i][1] -1] - xyc[i][2]
    if d < out:
        out=d

print(out)

Solution (Python):
n_a, n_b, n_m = map(int, input().split())

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

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

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

print(min(price))

Solution (Python):
a, b, m = input().split(' ')
m = int(m)
reizouko_list = [int(n) for n in input().split(' ')]
renji_list    = [int(n) for n in input().split(' ')]
yasui = min(reizouko_list) + min(renji_list)

for i in range(m):
  x, y, c = input().split(' ')
  x = int(x) - 1
  y = int(y) - 1
  c = int(c)
  if reizouko_list[x] + renji_list[y] - c < yasui:
    yasui = reizouko_list[x] + renji_list[y] - c
print(yasui)

Solution (Python):
A, B, M = map(int, input().split())
ref = list(map(int, input().split()))
mic = list(map(int, input().split()))
coupons = [ list(map(int, input().split())) for i in range(M)]
ans = min(ref) + min(mic)

for i in coupons:
  price = ref[i[0]-1] + mic[i[1]-1] - i[2]
  if price < ans:
    ans = price

print(ans)

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

al = list(map(int,input().split()))
bl = list(map(int,input().split()))

ans = min(al)+ min(bl)
temp = 0

for i in range(m):
  x,y,c =  map(int,input().split())
  temp = al[x-1] + bl[y-1] - c
  if temp < ans:
    ans = temp
print(ans)

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

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

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

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

z = []
result = min(As) + min(Bs)

for _ in range(M):
    a, b, m = map(int, input().split())
    k = As[a - 1] + Bs[b - 1] - m
    if result > k:
        result = k

print(result)

Solution (Python):
import sys
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 l in sys.stdin:
  xi,yi,ci = map(int,l.split())
  ans = min(ans,a[xi-1]+b[yi-1]-ci)
print(ans)

Solution (Python):
import numpy as np

def resolve():
    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)]
    

    
    i_no = np.argmin(al)
    j_no = np.argmin(bl)
    v_no= al[i_no] + bl[j_no]

    

    v_min = v_no
    for c in xyc:
        v = al[c[0]-1] + bl[c[1]-1] - c[2]
        if v < v_min:
            v_min = v

    print(v_min)

if __name__ == "__main__":
    resolve()

Solution (Python):



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

ans=min(a)+min(b)

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

Solution (Python):
def main():
    _, _, 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[x - 1] + b[y - 1] - c for x, y, c in xyc)
    ans = min(ans, min(a) + min(b))

    print(ans)


main()

Solution (Python):
A,B,M = map(int,input().split())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
	xi,yi,ci = map(int,input().split())
	if Ai[xi-1] + Bi[yi-1] - ci < min:
		min = Ai[xi-1] + Bi[yi-1] - ci
print(min)

Solution (Python):
input_line = [int(i) for i in input().split()]
a = input_line[0]
b = input_line[1]
m = input_line[2]

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

discount = []
for i in range(m):
    input_line = [int(j) for j in input().split()]
    a_i = input_line[0] - 1
    b_i = input_line[1] - 1
    c = input_line[2]
    discount.append([a_i, b_i, c])

min_price = min(a_list) + min(b_list)
for i in discount:
    discount_price = a_list[i[0]] + b_list[i[1]] - i[2]
    if min_price > discount_price:
        min_price = discount_price
print(min_price)

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

Solution (Python):
a,b,m = map(int,input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
s = min(la) + min(lb)

for i in range (m):
    x,y,c = map(int,input().split())
    t = la[x-1]+lb[y-1]-c
    if t < s:
        s = t
    else:
        s = s

print (s)

Solution (Python):
import sys

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 s in sys.stdin:
    x,y,c = map(int, s.split())
    tmp = a[x-1] + b[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()))
lst=[]
for i in range(m):
  x,y,c=map(int,input().split())
  lst.append([x,y,c])
v=min(A)+min(B)
for i in range(m):
  V=A[lst[i][0]-1]+B[lst[i][1]-1]-lst[i][2]
  if v>V:
    v=V
print(v)

Solution (Python):
a,b,m = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
a_min = min(a_list)
b_min = min(b_list)
ans = a_min + b_min

for i in range(m):
    x,y,z = map(int,input().split())
    if a_list[x-1] + b_list[y-1] - z < ans:
        ans = a_list[x-1] + b_list[y-1] - z
        
print(ans)

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

Min = min(F) + min(O)
for i in range(M):
    x,y,c = map(int,input().split(" "))
    f = F[x-1]
    o = O[y-1]
    C = f+o-c
    if C<Min:
        Min = C
print(Min)

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

min_price = min(a_list) + min(b_list)
for i in range(m):
    x, y, c = map(int, input().split())
    val = a_list[x-1] + b_list[y-1] - c
    if min_price > val:
        min_price = val

print(min_price)

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

m = []
for _ in range(M):
    x,y,c = list(map(int, input().split()))
    m.append([x,y,c])

nedan = min(a)+min(b)
for j in range(M):
    nedan = min(nedan,a[m[j][0]-1]+b[m[j][1]-1]-m[j][2])

print(nedan)

Solution (Python):

 
import math
import itertools
import sys
import copy

 







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


ans = sys.maxsize
for _ 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 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(M):
  c_temp = list(map(int, input().split()))
  c.append(c_temp)

min_price = min(a) + min(b)

for i in range(M):
  discount_price = a[c[i][0] - 1] + b[c[i][1] - 1] - c[i][2]
  if discount_price < min_price:
    min_price = discount_price

print(min_price)

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()))
    waribiki = []
    waribiki_result = 0

    for i in range(m):
        waribiki = list(map(int, input().split()))
        tmp_result = a_list[waribiki[0] - 1] + \
            b_list[waribiki[1] - 1] - waribiki[2]
        if i == 0:
            waribiki_result = tmp_result
        else:
            if tmp_result < waribiki_result:
                waribiki_result = tmp_result

    a_list.sort()
    b_list.sort()
    if a_list[0] + b_list[0] < waribiki_result:
        print(a_list[0] + b_list[0])
    else:
        print(waribiki_result)


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()))
xyc = [list(map(int, input().split())) for _ 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()))
ans = min(a) + min(b)
for _ in range(M):
    xi, yi, ci = map(int, input().split())
    ans = min(ans, a[xi - 1] + b[yi - 1] - ci)
print(ans)

Solution (Python):
A, B, M = map(int, input().split(' '))
aa = list(map(int, input().split(' ')))
bb = list(map(int, input().split(' ')))
cc = []
for _ in range(M):
    x, y, c = map(int, input().split(' '))
    cc.append([x, y, c])

ans = min(aa) + min(bb)
for x, y, c in cc:
    price = aa[x - 1] + bb[y - 1] - c
    if price < ans:
        ans = price

print(ans)

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

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

Ae = list(map(int, input().split()))
Be = list(map(int, input().split()))

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


ans = min(Ae) + min(Be)


for q in Queries:
    Ai = q[0] - 1
    Bi = q[1] - 1
    Disc = q[2]
    total = Ae[Ai] + Be[Bi] - Disc
    if total < ans:
        ans = total

print(ans)

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

def main():
    a, b, m = map(int, input().split())
    t_a = tuple(map(int, input().split()))
    t_b = tuple(map(int, input().split()))
    t_ken = [tuple(map(int, input().split())) for _ in range(m)]

    r = min(t_a) + min(t_b)
    for x, y, c in t_ken:
        r = min(r, t_a[x-1] + t_b[y-1] - c)
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
def getint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main(fr,el,discount):
    return fr+el-discount

freeze,elec,disc = getint()
frprice = getint()
elecprice = getint()
price = []
elec_min = elecprice[0]
for i in range(elec):
    elec_min = min(elec_min,elecprice[i])
fr_min = frprice[0]
for i in range(freeze):
    fr_min = min(fr_min,frprice[i])
price.append(fr_min+elec_min)

for i in range(disc):
    x,y,c = getint()
    price.append(main(frprice[x-1],elecprice[y-1],c))
ans = price[0]
for i in range(len(price)):
    ans = min(ans,price[i])
    
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)
lis = []
mi = 10**12
for i in range(m):
  x, y, c = map(int, input().split())
  s = a[x-1]+b[y-1]-c
  mi = min(s, mi)
mii = aa[0]+bb[0]
ans = min(mii,mi)
print(ans)

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

a_min = min(a_list)
b_min = min(b_list)

sum_min = a_min + b_min

for _ in range(m):
  m_0, m_1, m_2 = list(map(int, input().split(" ")))
  a_m = a_list[m_0 - 1]
  b_m = b_list[m_1 - 1]
  if sum_min > (a_m + b_m - m_2):
    sum_min = a_m + b_m - m_2
print(sum_min)

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

Solution (Python):
a,b,m=map(int,input().split())
alis=list(map(int,input().split()))
blis=list(map(int,input().split()))
ans=10**18
d=dict()
for i in range(m):
  x,y,c=map(int,input().split())
  x-=1
  y-=1
  d[(x,y)]=c
  ans=min(ans,alis[x]+blis[y]-c)
alis1=[]
blis1=[]
for i in range(a):
  alis1.append((alis[i],i))
for i in range(b):
  blis1.append((blis[i],i))
alis1.sort()
blis1.sort()
if (alis1[0][1],blis1[0][1]) not in d:
  ans=min(ans,alis1[0][0]+blis1[0][0])
print(ans)

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

cost_a = list(map(int, input().split()))
cost_b = list(map(int, input().split()))

ans = min(cost_a) + min(cost_b)

for m in range(M):
    coupon = list(map(int, input().split()))
    ans = min(ans, cost_a[coupon[0]-1]+cost_b[coupon[1]-1]-coupon[2])

print(ans)

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

a_items = list(map(int, input().split()))
b_items = list(map(int, input().split()))


m = min(a_items) + min(b_items)
value = m

for _ in range(M):
    x, y, c = list(map(int, input().split()))
    z = a_items[x-1] + b_items[y-1] - c

    if value > z:
        value = z

print(value)

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 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()))
x=[]
y=[]
c=[]
rei=[[]for i in range(A)]
for i in range(m):
    x1,y1,c1=map(int,input().split())
    x.append(x1-1)
    y.append(y1-1)
    c.append(c1)
    
    rei[x1-1].append(b[y1-1]-c1)


saisho=min(a)+min(b)

for i in range(m):
    gen=a[x[i]]+b[y[i]]-c[i]
    if(gen<saisho):
        saisho=gen

print(saisho)

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

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

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

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

discount = []
for i in [0]*M:
    discount.append(list(map(int,input().split())))

min_comb = min(a)+min(b)

for i in range(M):
    min_comb = min(min_comb,a[discount[i][0]-1]+b[discount[i][1]-1]-discount[i][2])
ans = min_comb
print(ans)