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):
inf = 10 ** 19    

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

    ans = inf

    for _ in range(m):
        x, y, c = map(int,input().split())
        tmp = a_list[x-1] + b_list[y-1] - c
        ans = min(ans, tmp)

    a_min = min(a_list)
    b_min = min(b_list)
        
    ans = min(ans, a_min+b_min)

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):


a, b, m = map(int, raw_input().split())
al = map(int, raw_input().split())
bl = map(int, raw_input().split())
mls = [map(int, raw_input().split()) for _ in xrange(m)]

minp = min(al) + min(bl)

for xi, yi, ci in mls:
    p = al[xi - 1] + bl[yi - 1] - ci
    minp = min(minp, p)

print minp

Solution (Python):
import numpy as np

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

an = np.asarray(input().split(), dtype=np.uint32)

bn = np.asarray(input().split(), dtype=np.uint32)

minimum = np.min(an) + np.min(bn)

for i in range(m):
    x, y, c = map(int, input().split())
    new_value = an[x-1] + bn[y-1] - c
    if minimum > new_value:
        minimum = new_value

print(minimum)

Solution (Python):
na, nb, nm = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_min, b_min = min(A), min(B)
min_tmp = a_min + b_min

aibjc = []
for _ in range(nm):
  ai, bj, c = list(map(int, input().split()))
  min_tmp = min(min_tmp, A[ai-1]+B[bj-1]-c)

print(min_tmp)

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())
  xyc.append(a[x-1]+b[y-1]-c)

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

Solution (Python):
a,b,m=map(int,input().split())
als=list(map(int,input().split()))
bls=list(map(int,input().split()))
mls=[list(map(int,input().split())) for i in range(m)]

ans=min(als)+min(bls)
for i in mls:
    aidx = i[0]-1
    bidx = i[1]-1
    cost = als[aidx]+bls[bidx]-i[2]
    if cost < ans:
        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()))

min_a = min(a)
min_b = min(b)

min_ab = min_a + min_b

min_wari = 10000000

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

if min_ab > min_wari:
    print(min_wari)
else:
    print(min_ab)

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

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

cand1 = min(A) + min(B) 
A_with_qupons = A[:]
B_with_qupons = B[:]
prices_with_qpons = [A[q[0]-1] + B[q[1]-1] - q[2] for q in qupons]
cand2 = min(prices_with_qpons) 
print(min([cand1, cand2]))

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    A, B, M = lr()
    a = lr()
    b = lr()
    ans = 10**6
    for i in range(M):
        x, y, c = lr()
        ans = min(ans, a[x-1]+b[y-1]-c)
    ans = min(ans, sorted(a)[0]+sorted(b)[0])
    print(ans)
resolve()

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

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

minimum = min(a) + min(b)

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

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(' ')))
    result = min(a_list) + min(b_list)
    for _ in range(M):
        x, y, c = map(int, input().split(' '))
        if result > a_list[x - 1] + b_list[y - 1] - c:
            result = a_list[x - 1] + b_list[y - 1] - c
    print(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_lst = []
for i in range(M):
    xyc_lst.append(list(map(int, input().split())))
ans = min(a) + min(b)
for i in range(M):
    x = xyc_lst[i][0]
    y = xyc_lst[i][1]
    c = xyc_lst[i][2]
    price = a[x-1] + b[y-1] - c
    if price < ans:
        ans = 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 = float('inf')
for i in range(M):
    x, y, c = map(int,input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)
print(min(min(a)+min(b), ans))

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()]
mina, minb = min(a), min(b)
minv = mina+minb
for _ in range(M):
    x, y, c = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    minv = min(minv, a[x]+b[y]-c)


print(minv)

Solution (Python):
a,b,m = map(int,input().split())        
a1 = list(map(int,input().split()))
b1 = list(map(int,input().split()))
ab = []
for _ in range(m):
    t = list(map(int,input().split()))
    ab.append(t)

ans = min(a1)+min(b1)

for i in ab:
    
    ans = min(ans, a1[i[0]-1]+b1[i[1]-1]-i[2])
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

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

if __name__ == '__main__':
    main()

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

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

ia = [int(s) for s in input().split()]
ib = [int(s) for s in input().split()]

mina = min(ia)
minb = min(ib)
mv = mina + minb

for x in range(m):
  vouch = [int(s) for s in input().split()]
  if mv >= ia[vouch[0]-1] + ib[vouch[1]-1] - vouch[2]:
    mv = ia[vouch[0]-1] + ib[vouch[1]-1] - vouch[2]

print(mv)

Solution (Python):
def solve():
    A, B, M = [int(x) for x in input().split(" ")]
    Ai = [int(x) for x in input().split(" ")]
    Bi = [int(x) for x in input().split(" ")]

    min_val = min(Ai) + min(Bi)

    for _ in range(M):
        x, y, c = input().split(" ")
        x = int(x) - 1
        y = int(y) - 1
        c = int(c)
        min_val = min(Ai[x] + Bi[y] - c, min_val)
    print(min_val)


solve()

Solution (Python):
A,B,M = map(int,input().split())
F = list(map(int,input().split()))
F.insert(0,10**6)
G = list(map(int,input().split()))
G.insert(0,10**6)
cmin = 10**6
for _ in range(M):
    x,y,c = map(int,input().split())
    cnt = F[x]+G[y]-c
    cmin = min(cmin,cnt)
F = sorted(F)
G = sorted(G)
cmin = min(cmin,F[0]+G[0])
print(cmin)

Solution (Python):
A,B,M = map(int,input().split())
Ali = list(map(int,input().split()))
Bli = list(map(int,input().split()))
C=[]
while True:
    try:
        C.append(list(map(int,input().split())))

    except:
        break;

notuse = min(Ali) + min(Bli)
minuse =10000000
for i in range(M):
    minuse = min(Ali[C[i][0]-1] +Bli[C[i][1]-1]-C[i][2],minuse)
print(min(minuse,notuse))

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)
ans = amin+bmin
for num in range(M):
    xi,yi,ci=map(int,input().split())
    a = ai[xi-1]
    b = bi[yi-1]
    new = a+b-ci
    if ans>new:
        ans=new
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 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())

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

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

dis = [[int(i) for i in input().split(' ')] for j in range(M)]

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

for d in dis:
  ans = a[d[0]-1] + b[d[1]-1] - d[2]
  ls.append(ans)
  
print(min(ls))

Solution (Python):
def main():
    _, _, m_num = map(int, input().split())
    a = [int(s) for s in input().split()]
    b = [int(s) for s in input().split()]

    min_price = min(a) + min(b)

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

main()

Solution (Python):
A,B,M=map(int,input().split())
C=list(map(int,input().split()))
D=list(map(int,input().split()))
a=10**5
b=10**5
for i in range(A):
    if(C[i]<a):
        a=C[i]
for i in range(B):
    if(D[i]<b):
        b=D[i]
k=a+b
for i in range(M):
    x,y,c=map(int,input().split())
    if((C[x-1]+D[y-1]-c)<k):
        k=C[x-1]+D[y-1]-c
print(k)

Solution (Python):

INF = int(1e6)
def main():
    a, b, m = map(int, input().split())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    cp = []
    ans1 = INF
    for _ in range(m):
        x, y, c = map(int, input().split())
        x -= 1
        y -= 1
        ans1 = min(a[x]+b[y]-c, ans1)
    a_cost = min(a)
    b_cost = min(b)
    ans2 = a_cost + b_cost
    ans = min(ans1, ans2) 
    print(ans)
main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

A,B,M = map(int,input().split(' '))
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
l_c = [list(map(int,input().split())) for _ in range(M)]

min_a = min(l_a)
min_b = min(l_b)

MIN = min_a+min_b

for i in range(M):
    k = l_c[i]
    x = k[0]
    y = k[1]
    c = k[2]
    m = l_a[x-1]+l_b[y-1]-c
    MIN = min(MIN,m)
print(MIN)

Solution (Python):



import sys
sys.setrecursionlimit(200000000)






def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    A,B,M=pin()
    a=list(pin())
    b=list(pin())
    ans=min(a)+min(b)
    
    for i in range(M):
       x,y,z=pin()
       ans=min(ans,a[x-1]+b[y-1]-z)
    print(ans)
    


"""


"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 3 1
3 3
3 3 3
1 2 1"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1 1 2
10
10
1 1 5
1 1 10"""
        output = """10"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 1
3 5
3 5
2 2 2"""
        output = """6"""
        self.assertIO(input, output)
if __name__=="__main__":resolve()

Solution (Python):
A_ref, B_range, M_waribiki = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

price = []
mini = min(A) + min(B)

price.append(mini)

for i in range(M_waribiki):
    x, y, redu = map(int, input().split())
    x -= 1
    y -= 1
    
    summ = A[x] + B[y] - redu
    
    price.append(summ)

print(min(price))

Solution (Python):
d = input().split(" ")
la = int(d[0])
lb = int(d[1])
lm = int(d[2])
a = input().split(" ")
mina = 100000
for i in range(la):
	a[i] = int(a[i])
	if mina > a[i]:
		mina = a[i]
b = input().split(" ")
minb = 100000
for i in range(lb):
	b[i] = int(b[i])
	if minb > b[i]:
		minb = b[i]
minab = mina + minb
for i in range(lm):
	d = input().split(" ")
	c = a[int(d[0])-1] + b[int(d[1])-1] - int(d[2])
	if c < minab:
		minab = c
print(minab)

Solution (Python):
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for i in range(m)]
ans = min(a)+min(b)
for i in range(m):
    price_a = a[xyc[i][0]-1]
    price_b = b[xyc[i][1]-1]
    c = xyc[i][2]
    ans = min(ans,price_a+price_b-c)
print(ans)

Solution (Python):

def main():
    a,b,m = map(int,input().split())
    reizouko = list(map(int,input().split()))
    mn_reizouko = min(reizouko)
    renji = list(map(int,input().split()))
    mn_renji = min(renji)
    mn = 20 ** 5 + 1
    for i in range(m):
        x,y,c = map(int,input().split())
        mn = min(mn,reizouko[x-1]+renji[y-1]-c)
    mn = min(mn,mn_reizouko+mn_renji)

    print(mn)




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 i in range(m) :
    X = list(map(int,input().split()))
    y = A[X[0]-1] + B[X[1]-1] - X[2]
    if y <= ans :
        ans = y
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)]

ans = min(a) + min(b)

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

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

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

min=min(a)+min(b)

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

print(min)

Solution (Python):
A, B, M = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]
xyc = [[int(i) for i in input().split()] for _ in range(M)]

print(min(min(al)+min(bl), min([al[m[0]-1] + bl[m[1]-1] - m[2] for m in xyc])))

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

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())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
min_A = min(A)
min_B = min(B)

C = []
d = []

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

print(min(min(C), min_A+min_B))

Solution (Python):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mn = min(b)
d = dd(list)
for _ in range(M):
  x, y, c = map(int, input().split())
  d[x - 1].append((y - 1, c))
res = float("inf")
for i in range(A):
  x = a[i]
  tt = mn + 0
  for t in d[i]:
    y, c = t
    tt = min(tt, b[y] - c)
  res = min(res, x + tt)
print(res)

Solution (Python):

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

mn = float('inf')
for tkt in range(m):
    x, y, c = map(int, input().split())
    tot = A[x-1] + B[y-1] - c
    mn = min(mn, tot)

mn = min(mn, min(A) + min(B))

print(mn)

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

ll=[] 
for i in range(m):
    ll.append(la[l[i][0]-1]+lb[l[i][1]-1]-l[i][2])

ll.append(min(la)+min(lb))
print(min(ll))

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

ans=min(a_l)+min(b_l)

for i in range(m):
    ans=min(ans, a_l[xyc[i][0]-1]+b_l[xyc[i][1]-1]-xyc[i][2])

print(ans)

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

ans = min(AList) + min(BList)
arr = []
arr.append(ans)

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

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

m = min(a) + min(b)

M = float('inf')
for x,y,c in xyc:
    x -= 1
    y -= 1
    tmp = a[x] + b[y] - c
    M = min(M,tmp)

if m>M:
    print(M)
else:
    print(m)

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

noti=min(a)+min(b)
ans=noti
c=0

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

ans=[]
for x,y,c in XYC:
  x,y=x-1,y-1
  ans.append(A[x]+B[y]-c)
A.sort()
B.sort()
ans.append(A[0]+B[0])
ans.sort()
print(ans[0])

Solution (Python):

A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = min(a_list) + min(b_list)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a_list[x - 1] + b_list[y - 1] - c)

print(ans)

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

for i in xls:
    
    ans = min(ans,als[i[0]-1]+bls[i[1]-1]-i[2])

print(ans)

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

minVal = min(a) + min(b)

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

print(minVal)

Solution (Python):
import sys


def read():
    return sys.stdin.readline().rstrip()


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


if __name__ == '__main__':
    main()

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math

import itertools



import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default






def main():
    A,B,M=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    wari=[]
    for i in range(M):
        x,y,c=map(int,input().split())
        wari.append([x,y,c])
    ans=min(a)+min(b)
    for i in range(M):
        temp=a[wari[i][0]-1]+b[wari[i][1]-1]-wari[i][2]
        ans=min(ans,temp)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):



import numpy as np
from numpy import newaxis, float32, float64, int32, int64, int16, int8, uint8, uint32, complex64, complex128



def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def func(a,b,m,
	aValues,
	bValues,
	xs,
	ys,
	cs):
	
	aValues=np.array(aValues)
	bValues=np.array(bValues)
	
	mi=aValues.min()+bValues.min()
	for x,y,c in zip(xs,ys,cs):
		v=aValues[x]+bValues[y]-c
		if v<mi: mi=v
		
	print(mi)
	



def main(inputs):
	a,b,m=getIntList(inputs[0])
	aValues=getIntList(inputs[1])
	bValues=getIntList(inputs[2])
	xs=np.empty(m, int32)
	ys=np.empty(m, int32)
	cs=np.empty(m, int32)
	for i in range(m):
		xs[i],ys[i],cs[i]=getIntList(inputs[3+i])
	xs-=1
	ys-=1
	







	func(a, b, m, aValues, bValues, xs, ys, cs)
	

if __name__=="__main__":
	inputs=getInputs()

	main(inputs)

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

main()

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

Solution (Python):
a, b, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
coupon = [list(map(int, input().split())) for i in range(m)]
cm = (10**5) * 2


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

a.sort()
b.sort()

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

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

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

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

res = min(alist) + min(blist)

for x, y, c in xyclist:
    cand = alist[x-1] + blist[y-1] - c
    if cand < res:
        res = cand

print(res)

Solution (Python):
A, B, N = 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 (N):
  W = list(map(int, input().split())) 
  x = W[0]-1
  y = W[1]-1
  c = W[2]
  price = La[x] + Lb[y] -c
  if price < ans:
    ans = price
print(ans)

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



print(ans)

Solution (Python):
A,B,m = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
min_tikets = 10000000
for i in range(m):
    x,y,c = list(map(int,input().split()))
    if a[x-1]+b[y-1]-c < min_tikets:
        min_tikets =a[x-1]+b[y-1]-c
a_sort=sorted(a)
b_sorted = sorted(b)
if a_sort[0]+b_sorted[0] < min_tikets:
    print(a_sort[0]+b_sorted[0])
else:
    print(min_tikets)

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()))
alst=list(map(int,input().split()))
blst=list(map(int,input().split()))

ans=10**10

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

    ans=min(ans,alst[x-1]+blst[y-1]-c)

ans=min(ans,min(alst)+min(blst))

print(ans)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = []
for _ in range(M):
    x, y, c = map(int, input().split())
    d.append((x-1, y-1, c))

ans = min(a) + min(b)

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

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

cand = []
for i in range(M):
    lx, ly, lc = map(int, input().split())
    x.append(lx)
    y.append(ly)
    c.append(lc)

cand.append(min(a)+min(b))
for i in range(M):
    cand.append(a[x[i]-1] + b[y[i]-1] - c[i])

ans = min(cand)
print(ans)

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

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
import bisect
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,M = IL()
a = IL()
b = IL()
xyc = [IL() for i 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)

"""
3 2 1
3 5 4
3 5
2 2 2
"""

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

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

ma = 10**9
mb = 10**9
for j in range(A):
  ma = min(ma,a[j])
for k in range(B):
  mb = min(mb,b[k])
ans = min(ans,ma+mb)
print(ans)

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

ans = min(frid) + min(mic)

for _ in range(m):
    x, y, c = map(int, input().split())
    disc = frid[x-1] + mic[y-1] - c

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

Solution (Python):

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

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

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

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

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

Solution (Python):
def main():
    A,B,M=map(int, input().split())
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    
    min_a = min(a)
    min_b = min(b)
    ans = min_a + min_b

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

if __name__ == '__main__':
    main()